ScopeMap

Struct ScopeMap 

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

Source

pub fn new() -> ScopeMap<K, V, RandomState>

Creates an empty ScopeMap with a default hasher and capacity.

Source

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>

Source

pub fn with_hasher(hash_builder: S) -> Self

Creates an empty ScopeMap with the specified hasher and a default capacity.

Source

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self

Creates an empty ScopeMap with the specified hasher and capacity.

Source

pub fn capacity(&self) -> usize

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

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

pub fn len(&self) -> usize

Gets the number of unique keys in the map.

Source

pub fn depth(&self) -> usize

Gets the number of layers in the map.

Source§

impl<K, V, S> ScopeMap<K, V, S>
where S: BuildHasher,

Source

pub fn push_layer(&mut self)

Adds a new, empty layer.

Computes in O(1) time.

Source

pub fn pop_layer(&mut self) -> bool

Removes the topmost layer (if it isn’t the bottom layer) and all associated keys/values. Returns true if a layer was removed.

Computes in O(n) time in relation to the number of keys stored in the removed layer.

Source§

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

Source

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

Returns true if the map contains the specified key in any layer.

Computes in O(1) time.

Source

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

Returns true if the map contains the specified key at the top layer.

Computes in O(1) time.

Source

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

Gets a reference to the topmost value associated with a key.

Computes in O(1) time.

Source

pub fn get_all<Q>(&self, key: &Q) -> Option<impl Iterator<Item = &V>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

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

Gets a mutable reference to the topmost value associated with a key.

Computes in O(1) time.

Source

pub fn get_all_mut<Q>( &mut self, key: &Q, ) -> Option<impl Iterator<Item = &mut V>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parent<Q>(&self, key: &Q, min_depth: usize) -> Option<&V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parent_depth<Q>( &self, key: &Q, min_depth: usize, ) -> Option<(&V, usize)>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parent_height<Q>( &self, key: &Q, min_depth: usize, ) -> Option<(&V, usize)>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parents<Q>( &self, key: &Q, min_depth: usize, ) -> Option<impl Iterator<Item = &V>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parent_mut<Q>(&mut self, key: &Q, min_depth: usize) -> Option<&mut V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn get_parents_mut<Q>( &mut self, key: &Q, min_depth: usize, ) -> Option<impl Iterator<Item = &mut V>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn depth_of<Q>(&self, key: &Q) -> Option<usize>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn height_of<Q>(&self, key: &Q) -> Option<usize>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

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.

Source

pub fn define(&mut self, key: K, value: V)

Adds the specified entry to the topmost layer.

Source

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.

Source

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

Removes the entry with the specified key from the topmost layer and returns its value.

Source

pub fn clear_top(&mut self)

Removes all entries in the topmost layer.

Source

pub fn clear_all(&mut self)

Removes all elements and additional layers.

Source

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

Source

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

Source

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

Source

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

Iterates over all keys in arbitrary order.

The iterator element type is &'a K.

Source

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

Iterates over all keys in the topmost layer in arbitrary order.

The iterator element type is &'a K.

Trait Implementations§

Source§

impl<K: Clone, V: Clone, S: Clone + BuildHasher> Clone for ScopeMap<K, V, S>

Source§

fn clone(&self) -> ScopeMap<K, V, S>

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: Default + BuildHasher> Default for ScopeMap<K, V, S>

Source§

fn default() -> Self

Creates a new ScopeMap with the default configuration.

Source§

impl<K, Q, V, S> Index<&Q> for ScopeMap<K, V, S>
where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized, S: BuildHasher,

Source§

fn index(&self, index: &Q) -> &Self::Output

Returns a reference to the value associated with the provided key.

§Panics

Panics if the key does not exist in the ScopeMap.

Source§

type Output = V

The returned type after indexing.

Auto Trait Implementations§

§

impl<K, V, S> Freeze for ScopeMap<K, V, S>
where S: Freeze,

§

impl<K, V, S> RefUnwindSafe for ScopeMap<K, V, S>

§

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

§

impl<K, V, S> Sync for ScopeMap<K, V, S>
where S: Sync, K: Sync, V: Sync,

§

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

§

impl<K, V, S> UnwindSafe for ScopeMap<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.