pub struct RefCountedHashMap<K, V> { /* private fields */ }
Expand description
A HashMap
which keeps a reference count for each entry.
Implementations§
Source§impl<K: Eq + Hash, V> RefCountedHashMap<K, V>
impl<K: Eq + Hash, V> RefCountedHashMap<K, V>
Sourcepub fn insert_with<O, F: FnOnce() -> (V, O)>(
&mut self,
key: K,
f: F,
) -> InsertResult<O>
pub fn insert_with<O, F: FnOnce() -> (V, O)>( &mut self, key: K, f: F, ) -> InsertResult<O>
Increments the reference count of the entry with the given key.
If the key isn’t in the map, the given function is called to create its associated value.
Sourcepub fn remove(&mut self, key: K) -> RemoveResult<V>
pub fn remove(&mut self, key: K) -> RemoveResult<V>
Decrements the reference count of the entry with the given key.
If the reference count reaches 0, the entry will be removed and its value returned.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true
if the map contains a value for the specified key.
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn iter_mut<'a>(
&'a mut self,
) -> impl 'a + Iterator<Item = (&'a K, &'a mut V)>
pub fn iter_mut<'a>( &'a mut self, ) -> impl 'a + Iterator<Item = (&'a K, &'a mut V)>
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values.
Sourcepub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = (&'a K, &'a V)> + Clone
pub fn iter<'a>(&'a self) -> impl 'a + Iterator<Item = (&'a K, &'a V)> + Clone
An iterator visiting all key-value pairs in arbitrary order, with non-mutable references to the values.
Sourcepub fn iter_ref_counts<'a>(
&'a self,
) -> impl 'a + Iterator<Item = (&'a K, &'a NonZeroUsize)> + Clone
pub fn iter_ref_counts<'a>( &'a self, ) -> impl 'a + Iterator<Item = (&'a K, &'a NonZeroUsize)> + Clone
An iterator visiting all keys in arbitrary order with the reference count for each key.