SecondaryMap

Trait SecondaryMap 

Source
pub trait SecondaryMap<K, V> {
    type Iter<'a>: Iterator<Item = (K, &'a V)> + 'a
       where Self: 'a,
             K: 'a,
             V: 'a;

    // Required methods
    fn new() -> Self;
    fn with_capacity(capacity: usize) -> Self;
    fn default_value(&self) -> V;
    fn ensure_capacity(&mut self, capacity: usize);
    fn capacity(&self) -> usize;
    fn get(&self, key: K) -> &V;
    fn set(&mut self, key: K, val: V);
    fn take(&mut self, key: K) -> V;
    fn iter<'a>(&'a self) -> Self::Iter<'a>
       where K: 'a,
             V: 'a;

    // Provided methods
    fn remove(&mut self, key: K) { ... }
    fn rekey(&mut self, old: K, new: Option<K>) { ... }
    fn swap(&mut self, key0: K, key1: K)
       where K: Clone,
             V: Clone { ... }
}
Expand description

A map from keys to values with default elements.

Querying a key that has not been set returns a default value.

Required Associated Types§

Source

type Iter<'a>: Iterator<Item = (K, &'a V)> + 'a where Self: 'a, K: 'a, V: 'a

An iterator over the non-default entries of the secondary map.

Required Methods§

Source

fn new() -> Self

Creates a new secondary map.

Source

fn with_capacity(capacity: usize) -> Self

Creates a new secondary map with specified capacity.

Source

fn default_value(&self) -> V

Returns the default value for the secondary map. Any key that has not been set will return this value.

Source

fn ensure_capacity(&mut self, capacity: usize)

Increases the capacity of the secondary map to capacity.

Source

fn capacity(&self) -> usize

Returns the maximum index the secondary map can contain without allocating.

Source

fn get(&self, key: K) -> &V

Immutably borrows the value at a key.

Returns a borrow of the default value when no value has been set for the key.

Source

fn set(&mut self, key: K, val: V)

Sets the value at a key.

Source

fn take(&mut self, key: K) -> V

Takes the value at a key, leaving default() behind.

Source

fn iter<'a>(&'a self) -> Self::Iter<'a>
where K: 'a, V: 'a,

Returns an iterator over the non-default entries of the secondary map.

Provided Methods§

Source

fn remove(&mut self, key: K)

Removes the value at a key, leaving default() behind.

Source

fn rekey(&mut self, old: K, new: Option<K>)

Remove key old and optionally move to key new.

This method is useful for rekey callbacks such as in PortMut::set_num_ports and PortMut::compact_nodes.

Source

fn swap(&mut self, key0: K, key1: K)
where K: Clone, V: Clone,

Swaps the values of two keys.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<K> SecondaryMap<K, bool> for HashSet<K>
where K: Hash + Eq + Clone,

Source§

type Iter<'a> = HashSetIter<'a, K> where Self: 'a, K: 'a

Source§

fn new() -> Self

Source§

fn with_capacity(capacity: usize) -> Self

Source§

fn default_value(&self) -> bool

Source§

fn ensure_capacity(&mut self, capacity: usize)

Source§

fn capacity(&self) -> usize

Source§

fn get(&self, key: K) -> &bool

Source§

fn set(&mut self, key: K, val: bool)

Source§

fn take(&mut self, key: K) -> bool

Source§

fn iter<'a>(&'a self) -> Self::Iter<'a>
where K: 'a,

Source§

impl<K> SecondaryMap<K, bool> for BitVec
where K: Into<usize> + TryFrom<usize>,

Source§

type Iter<'a> = BitVecIter<'a, K> where Self: 'a, K: 'a

Source§

fn new() -> Self

Source§

fn with_capacity(capacity: usize) -> Self

Source§

fn default_value(&self) -> bool

Source§

fn ensure_capacity(&mut self, capacity: usize)

Source§

fn capacity(&self) -> usize

Source§

fn get(&self, key: K) -> &bool

Source§

fn set(&mut self, key: K, val: bool)

Source§

fn take(&mut self, key: K) -> bool

Source§

fn rekey(&mut self, old: K, new: Option<K>)

Source§

fn swap(&mut self, key0: K, key1: K)

Source§

fn iter<'a>(&'a self) -> Self::Iter<'a>
where K: 'a,

Implementors§

Source§

impl<K, V> SecondaryMap<K, V> for UnmanagedDenseMap<K, V>
where K: Into<usize> + TryFrom<usize> + Copy, V: Clone + Default,

Source§

type Iter<'a> = UnmanagedIter<'a, K, V> where Self: 'a, K: 'a, V: 'a