pub struct TransientMap<K, V, S = RandomState> { /* private fields */ }Expand description
A hashmap wrapper which tracks used and unused entries, allowing for their efficient removal.
Implementations§
Source§impl<K, V> TransientMap<K, V, RandomState>
impl<K, V> TransientMap<K, V, RandomState>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty TransientMap with at least the specified capacity.
Source§impl<K, V, S> TransientMap<K, V, S>
impl<K, V, S> TransientMap<K, V, S>
Sourcepub fn set_all_used(&mut self)
pub fn set_all_used(&mut self)
Marks all entries as used. They will not be included
in the next drain_unused call. This function is O(1).
Sourcepub fn set_all_unused(&mut self)
pub fn set_all_unused(&mut self)
Marks all entries as unused. They will be included in the
next drain_unused call. This function is O(1).
Sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self
Creates an empty TransientMap with at least the specified capacity, using
hasher to hash the keys.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
Sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K.
Sourcepub fn keys_silent(&self) -> impl Iterator<Item = &K>
pub fn keys_silent(&self) -> impl Iterator<Item = &K>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K. The iterator visits
all keys silently, meaning that nothing is marked as used.
Sourcepub fn into_keys(self) -> impl Iterator<Item = K>
pub fn into_keys(self) -> impl Iterator<Item = K>
Creates a consuming iterator visiting all the keys in arbitrary order.
The map cannot be used after calling this.
The iterator element type is K.
Sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V.
Sourcepub fn values_silent(&self) -> impl Iterator<Item = &V>
pub fn values_silent(&self) -> impl Iterator<Item = &V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V. The iterator visits
all keys silently, meaning that nothing is marked as used.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
An iterator visiting all values mutably in arbitrary order.
The iterator element type is &'a mut V.
Sourcepub fn into_values(self) -> impl Iterator<Item = V>
pub fn into_values(self) -> impl Iterator<Item = V>
Creates a consuming iterator visiting all the values in arbitrary order.
The map cannot be used after calling this.
The iterator element type is V.
Sourcepub fn iter(&self) -> impl '_ + Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl '_ + Iterator<Item = (&K, &V)>
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V).
Sourcepub fn iter_silent(&self) -> impl '_ + Iterator<Item = (&K, &V)>
pub fn iter_silent(&self) -> impl '_ + Iterator<Item = (&K, &V)>
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V). The iterator visits
all keys silently, meaning that nothing is marked as used.
Sourcepub fn iter_mut(&mut self) -> impl '_ + Iterator<Item = (&K, &mut V)>
pub fn iter_mut(&mut self) -> impl '_ + Iterator<Item = (&K, &mut V)>
An iterator visiting all key-value pairs in arbitrary order,
with mutable references to the values.
The iterator element type is (&'a K, &'a mut V).
Sourcepub fn drain(&mut self) -> impl '_ + Iterator<Item = (K, V)>
pub fn drain(&mut self) -> impl '_ + Iterator<Item = (K, V)>
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
If the returned iterator is dropped before being fully consumed, it drops the remaining key-value pairs. The returned iterator keeps a mutable borrow on the map to optimize its implementation.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher.
Source§impl<K, V, S> TransientMap<K, V, S>
impl<K, V, S> TransientMap<K, V, S>
Sourcepub fn drain_unused(&mut self) -> impl '_ + Iterator<Item = (K, V)>
pub fn drain_unused(&mut self) -> impl '_ + Iterator<Item = (K, V)>
Removes all entries from the map that were not accessed since the
last call to drain_used or drain_unused.
It takes O(unused elements) time to iterate over the results of this call.
Like the standard hash_map::Drain, all elements remaining in the iterator
when it is dropped are also dropped.
Sourcepub fn drain_used(&mut self) -> impl '_ + Iterator<Item = (K, V)>
pub fn drain_used(&mut self) -> impl '_ + Iterator<Item = (K, V)>
Removes all entries from the map that were accessed since the
last call to drain_used or drain_unused.
It takes O(used elements) time to iterate over the results of this call.
Like the standard hash_map::Drain, all elements remaining in the iterator
when it is dropped are also dropped.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted
in the TransientMap. The collection may reserve more space to speculatively
avoid frequent reallocations. After calling reserve,
capacity will be greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate. Because the predicate visits all elements, all elements are marked as used.
In other words, remove all pairs (k, v) for which f(&k, &mut v) returns false.
The elements are visited in unsorted (and unspecified) order.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional more elements to be inserted
in the TransientMap. The collection may reserve more space to speculatively
avoid frequent reallocations. After calling try_reserve,
capacity will be greater than or equal to self.len() + additional if
it returns Ok(()).
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop down no lower than the supplied limit while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
Sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_silent<Q>(&self, k: &Q) -> Option<&V>
pub fn get_silent<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key. This accesses the value silently, meaning that nothing is marked as used.
Sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
Sourcepub fn get_key_value_silent<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value_silent<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key. This accesses the pair silently, meaning that nothing is marked as used.
Sourcepub fn contains_key_silent<Q>(&self, k: &Q) -> bool
pub fn contains_key_silent<Q>(&self, k: &Q) -> bool
Returns true if the map contains a value for the specified key. This accesses
the value silently, meaning that nothing is marked as used.
Sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map. The inserted key is automatically treated as used.
Sourcepub fn insert_unused(&mut self, k: K, v: V) -> Option<V>
pub fn insert_unused(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map. The inserted key is initially considered unused.