use fxhash::FxBuildHasher;
use indexmap::IndexMap;
use libipld::Cid;
#[derive(Debug, Clone, PartialEq)]
pub struct LinkMap<T>(IndexMap<Cid, T, FxBuildHasher>);
impl<T> Default for LinkMap<T> {
fn default() -> Self {
Self(IndexMap::with_hasher(FxBuildHasher::default()))
}
}
impl<T> LinkMap<T> {
pub fn take(self) -> IndexMap<Cid, T, FxBuildHasher> {
self.0
}
pub fn take_ref(&self) -> &IndexMap<Cid, T, FxBuildHasher> {
&self.0
}
pub fn len(&self) -> u32 {
self.0.len() as u32
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn insert(&mut self, cid: Cid, value: T) {
self.0.insert(cid, value);
}
pub fn get(&self, cid: &Cid) -> Option<&T> {
self.0.get(cid)
}
pub fn entry(&mut self, cid: Cid) -> indexmap::map::Entry<'_, Cid, T> {
self.0.entry(cid)
}
pub fn contains_key(&self, cid: &Cid) -> bool {
self.0.contains_key(cid)
}
}