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 PortGraph::set_num_ports and PortGraph::compact_nodes.

source

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

Swaps the values of two keys.

Implementations on Foreign Types§

source§

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

§

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

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,

source§

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

§

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

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,

Implementors§

source§

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

§

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