[][src]Struct quickscope::ScopeMap

pub struct ScopeMap<K, V, S: BuildHasher = RandomState> { /* fields omitted */ }

A layered hash map for representing scoped variables and their values.

Implementations

impl<K, V> ScopeMap<K, V, RandomState>[src]

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

Creates an empty ScopeMap with a default hasher and capacity.

pub fn with_capacity(capacity: usize) -> ScopeMap<K, V, RandomState>[src]

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

impl<K, V, S: BuildHasher> ScopeMap<K, V, S>[src]

pub fn with_hasher(hash_builder: S) -> Self[src]

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

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

Creates an empty ScopeMap with the specified hasher and capacity.

pub fn capacity(&self) -> usize[src]

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

pub fn is_empty(&self) -> bool[src]

Returns true if the map is empty.

pub fn len(&self) -> usize[src]

Gets the number of unique keys in the map.

pub fn depth(&self) -> usize[src]

Gets the number of layers in the map.

impl<K, V, S> ScopeMap<K, V, S> where
    S: BuildHasher
[src]

pub fn push_layer(&mut self)[src]

Adds a new, empty layer.

Computes in O(1) time.

pub fn pop_layer(&mut self) -> bool[src]

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.

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

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

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

Computes in O(1) time.

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

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

Computes in O(1) time.

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

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

Computes in O(1) time.

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

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.

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

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

Computes in O(1) time.

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

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.

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

Gets a reference to a value skip_count layers below the topmost value associated with a key. Saturates to base layer.

Computes in O(n) time (worst-case) in relation to skip_count.

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

Gets an iterator over references to all values skip_count layers below the topmost value associated with a key. Saturates to base layer.

Computes in O(n) time (worst-case) in relation to skip_count.

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

Gets a mutable reference to a value skip_count layers below the topmost value associated with a key. Saturates to base layer.

Computes in O(n) time (worst-case) in relation to skip_count.

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

Gets an iterator over mutable references to all values skip_count layers below the topmost value associated with a key. Saturates to base layer.

Computes in O(n) time (worst-case) in relation to skip_count.

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

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.

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

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.

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

Adds the specified entry to the topmost layer.

pub fn define_parent(&mut self, key: K, value: V, skip_count: usize)[src]

Adds the specified entry in the layer skip_count layers from the top. Saturates to base layer.

pub fn delete(&mut self, key: K) -> bool[src]

Removes the entry with the specified key from the topmost layer.

pub fn clear_top(&mut self)[src]

Removes all entries in the topmost layer.

pub fn clear_all(&mut self)[src]

Removes all elements and additional layers.

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>[src]

Iterates over all key-value pairs in arbitrary order.

The iterator element type is (&'a K, &'a V).

pub fn iter_top(&self) -> impl Iterator<Item = (&K, &V)>[src]

Iterates over all key-value pairs in the topmost layer in arbitrary order.

The iterator element type is (&'a K, &'a V).

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>[src]

Iterates over all key-value pairs in arbitrary order, allowing mutation of the values.

The iterator element type is (&'a K, &'a mut V).

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

Iterates over all keys in arbitrary order.

The iterator element type is &'a K.

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

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

The iterator element type is &'a K.

Trait Implementations

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

impl<K, V, S: Default + BuildHasher> Default for ScopeMap<K, V, S>[src]

fn default() -> Self[src]

Creates a new ScopeMap with the default configuration.

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

type Output = V

The returned type after indexing.

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

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

Panics

Panics if the key does not exist in the ScopeMap.

Auto Trait Implementations

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

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

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

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

impl<K, V, S> UnwindSafe for ScopeMap<K, V, S> where
    K: UnwindSafe,
    S: UnwindSafe,
    V: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.