use super::*;
use cid::Cid;
#[cfg(doc)]
use std::collections::HashSet;
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct CidHashSet {
inner: CidHashMap<()>,
}
impl CidHashSet {
pub fn new() -> Self {
Self::default()
}
pub fn insert(&mut self, cid: Cid) -> bool {
self.inner.insert(cid, ()).is_none()
}
pub fn len(&self) -> usize {
self.inner.len()
}
#[allow(dead_code)]
pub fn contains(&self, cid: &Cid) -> bool {
self.inner.contains_key(cid)
}
#[allow(dead_code)]
pub fn remove(&mut self, cid: &Cid) -> bool {
self.inner.remove(cid).is_some()
}
#[allow(dead_code)]
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}
impl Extend<Cid> for CidHashSet {
fn extend<T: IntoIterator<Item = Cid>>(&mut self, iter: T) {
self.inner.extend(iter.into_iter().map(|it| (it, ())))
}
}
impl FromIterator<Cid> for CidHashSet {
fn from_iter<T: IntoIterator<Item = Cid>>(iter: T) -> Self {
let mut this = Self::new();
this.extend(iter);
this
}
}