pub struct ScopeMap<K, V, S: BuildHasher = RandomState> { /* private fields */ }Expand description
A layered hash map for representing scoped variables and their values.
Implementations§
Source§impl<K, V> ScopeMap<K, V, RandomState>
impl<K, V> ScopeMap<K, V, RandomState>
Sourcepub fn new() -> ScopeMap<K, V, RandomState>
pub fn new() -> ScopeMap<K, V, RandomState>
Creates an empty ScopeMap with a default hasher and capacity.
Sourcepub fn with_capacity(capacity: usize) -> ScopeMap<K, V, RandomState>
pub fn with_capacity(capacity: usize) -> ScopeMap<K, V, RandomState>
Creates an empty ScopeMap with a default hasher and the specified capacity.
Source§impl<K, V, S: BuildHasher> ScopeMap<K, V, S>
impl<K, V, S: BuildHasher> ScopeMap<K, V, S>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty ScopeMap with the specified hasher and a default capacity.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates an empty ScopeMap with the specified hasher and capacity.
Source§impl<K, V, S> ScopeMap<K, V, S>where
S: BuildHasher,
impl<K, V, S> ScopeMap<K, V, S>where
S: BuildHasher,
Sourcepub fn push_layer(&mut self)
pub fn push_layer(&mut self)
Adds a new, empty layer.
Computes in O(1) time.
Source§impl<K: Eq + Hash, V, S: BuildHasher> ScopeMap<K, V, S>
impl<K: Eq + Hash, V, S: BuildHasher> ScopeMap<K, V, S>
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains the specified key in any layer.
Computes in O(1) time.
Sourcepub fn contains_key_at_top<Q>(&self, key: &Q) -> bool
pub fn contains_key_at_top<Q>(&self, key: &Q) -> bool
Returns true if the map contains the specified key at the top layer.
Computes in O(1) time.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Gets a reference to the topmost value associated with a key.
Computes in O(1) time.
Sourcepub fn get_all<Q>(&self, key: &Q) -> Option<impl Iterator<Item = &V>>
pub fn get_all<Q>(&self, key: &Q) -> Option<impl Iterator<Item = &V>>
Gets an iterator over references to all the values associated with a key, starting with the topmost and going down.
Computes in O(1) time.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Gets a mutable reference to the topmost value associated with a key.
Computes in O(1) time.
Sourcepub fn get_all_mut<Q>(
&mut self,
key: &Q,
) -> Option<impl Iterator<Item = &mut V>>
pub fn get_all_mut<Q>( &mut self, key: &Q, ) -> Option<impl Iterator<Item = &mut V>>
Gets an iterator over mutable references to all the values associated with a key, starting with the topmost and going down.
Computes in O(1) time.
Sourcepub fn get_parent<Q>(&self, key: &Q, min_depth: usize) -> Option<&V>
pub fn get_parent<Q>(&self, key: &Q, min_depth: usize) -> Option<&V>
Gets a reference to a value min_depth layers below the topmost value associated with a key.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn get_parent_depth<Q>(
&self,
key: &Q,
min_depth: usize,
) -> Option<(&V, usize)>
pub fn get_parent_depth<Q>( &self, key: &Q, min_depth: usize, ) -> Option<(&V, usize)>
Gets a reference to the value associated with a key at least min_depth layers below the topmost layer, as well as its associated depth.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn get_parent_height<Q>(
&self,
key: &Q,
min_depth: usize,
) -> Option<(&V, usize)>
pub fn get_parent_height<Q>( &self, key: &Q, min_depth: usize, ) -> Option<(&V, usize)>
Gets a reference to the value associated with a key at least min_depth layers below the topmost layer, as well as its associated height.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn get_parents<Q>(
&self,
key: &Q,
min_depth: usize,
) -> Option<impl Iterator<Item = &V>>
pub fn get_parents<Q>( &self, key: &Q, min_depth: usize, ) -> Option<impl Iterator<Item = &V>>
Gets an iterator over references to all values min_depth layers below the topmost value associated with a key.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn get_parent_mut<Q>(&mut self, key: &Q, min_depth: usize) -> Option<&mut V>
pub fn get_parent_mut<Q>(&mut self, key: &Q, min_depth: usize) -> Option<&mut V>
Gets a mutable reference to a value min_depth layers below the topmost value associated with a key.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn get_parents_mut<Q>(
&mut self,
key: &Q,
min_depth: usize,
) -> Option<impl Iterator<Item = &mut V>>
pub fn get_parents_mut<Q>( &mut self, key: &Q, min_depth: usize, ) -> Option<impl Iterator<Item = &mut V>>
Gets an iterator over mutable references to all values min_depth layers below the topmost value associated with a key.
Saturates to base layer.
Computes in O(n) time (worst-case) in relation to min_depth.
Sourcepub fn depth_of<Q>(&self, key: &Q) -> Option<usize>
pub fn depth_of<Q>(&self, key: &Q) -> Option<usize>
Gets the depth of the specified key (i.e. how many layers down from the top that the key first appears). A depth of 0 refers to the top layer.
Returns None if the key does not exist.
Computes in O(n) time (worst-case) in relation to layer count.
Sourcepub fn height_of<Q>(&self, key: &Q) -> Option<usize>
pub fn height_of<Q>(&self, key: &Q) -> Option<usize>
Gets the height of the specified key (i.e. how many layers up from the bottom that the key last appears). A height of 0 refers to the bottom layer.
Returns None if the key does not exist.
Computes in O(n) time (worst-case) in relation to layer count.
Sourcepub fn define_parent(&mut self, key: K, value: V, min_depth: usize)
pub fn define_parent(&mut self, key: K, value: V, min_depth: usize)
Adds the specified entry in the layer min_depth layers from the top. Saturates to base layer.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes the entry with the specified key from the topmost layer and returns its value.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Iterates over all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V).
Sourcepub fn iter_top(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter_top(&self) -> impl Iterator<Item = (&K, &V)>
Iterates over all key-value pairs in the topmost layer in arbitrary order.
The iterator element type is (&'a K, &'a V).
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
Iterates over all key-value pairs in arbitrary order, allowing mutation of the values.
The iterator element type is (&'a K, &'a mut V).