TransientMap

Struct TransientMap 

Source
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>

Source

pub fn new() -> Self

Creates an empty TransientMap.

Source

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>

Source

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).

Source

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).

Source

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.

Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

An iterator visiting all keys in arbitrary order. The iterator element type is &'a K.

Source

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.

Source

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.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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).

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

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.

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Source

pub fn hasher(&self) -> &S

Returns a reference to the map’s BuildHasher.

Source§

impl<K, V, S> TransientMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

Source

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.

Source

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.

Source

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.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

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.

Source

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(()).

Source

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.

Source

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.

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Gets the given key’s corresponding entry in the map for in-place manipulation.

Source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value corresponding to the key.

Source

pub fn get_silent<Q>(&self, k: &Q) -> Option<&V>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value corresponding to the key. This accesses the value silently, meaning that nothing is marked as used.

Source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the key-value pair corresponding to the supplied key.

Source

pub fn get_key_value_silent<Q>(&self, k: &Q) -> Option<(&K, &V)>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the key-value pair corresponding to the supplied key. This accesses the pair silently, meaning that nothing is marked as used.

Source

pub fn contains_key_silent<Q>(&self, k: &Q) -> bool
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns true if the map contains a value for the specified key. This accesses the value silently, meaning that nothing is marked as used.

Source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a mutable reference to the value corresponding to the key.

Source

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.

Source

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.

Source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes a key from the map, returning the value at the key if the key was previously in the map.

Source

pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where Rc<K>: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes a key from the map, returning the stored key and value if the key was previously in the map.

Trait Implementations§

Source§

impl<K, V, S> Clone for TransientMap<K, V, S>
where K: Clone, V: Clone, S: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, S> Debug for TransientMap<K, V, S>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, S> Default for TransientMap<K, V, S>
where S: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a TransientMap<K, V, S>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)> + 'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a mut TransientMap<K, V, S>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a mut V)> + 'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V, S> IntoIterator for TransientMap<K, V, S>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V, S> PartialEq for TransientMap<K, V, S>
where K: Eq + Hash, V: PartialEq, S: BuildHasher,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V, S> Eq for TransientMap<K, V, S>
where K: Eq + Hash, V: Eq, S: BuildHasher,

Source§

impl<K, V, S> Send for TransientMap<K, V, S>
where K: Send, V: Send, S: Send,

Auto Trait Implementations§

§

impl<K, V, S = RandomState> !Freeze for TransientMap<K, V, S>

§

impl<K, V, S = RandomState> !RefUnwindSafe for TransientMap<K, V, S>

§

impl<K, V, S = RandomState> !Sync for TransientMap<K, V, S>

§

impl<K, V, S> Unpin for TransientMap<K, V, S>
where S: Unpin, V: Unpin,

§

impl<K, V, S = RandomState> !UnwindSafe for TransientMap<K, V, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.