Struct bisetmap::BisetMap
[−]
[src]
pub struct BisetMap<L: Eq + Hash + Clone, R: Eq + Hash + Clone> { /* fields omitted */ }
A two-way map between keys (left) and values (right).
See the module-level documentation for more details and examples.
Methods
impl<L: Eq + Hash + Clone, R: Eq + Hash + Clone> BisetMap<L, R>
[src]
fn new() -> BisetMap<L, R>
[src]
Creates an empty BisetMap
.
Examples
use bisetmap::BisetMap; let bmap: BisetMap<char, u32> = BisetMap::new();
fn with_capacity(capacity: usize) -> BisetMap<L, R>
[src]
Creates an empty BisetMap
with the given capacity.
Examples
use bisetmap::BisetMap; let bmap: BisetMap<char, u32> = BisetMap::with_capacity(5);
fn clear(&self)
[src]
Removes all key-value pairs from the BisetMap
, but keeps the allocated memory for reuse.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('b', 2); bmap.insert('c', 3); bmap.clear(); assert!(bmap.len() == 0);
fn rev(&self) -> BisetMap<R, L>
[src]
Returns a new BisetMap where keys and values are swapped.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('b', 2); bmap.insert('c', 3); let rmap = bmap.rev(); assert_eq!(rmap.get(&1), ['a']);
fn collect(&self) -> Vec<(L, Vec<R>)>
[src]
Returns a vector of (key,values) pairs, where values itself is a vector. (Order of all pairs is unknown)
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('a', 2); bmap.insert('b', 3); assert_eq!(bmap.collect(), vec![('a',vec![1,2]), ('b',vec![3])]);
fn flat_collect(&self) -> Vec<(L, R)>
[src]
Returns a vector of (key,value) pairs. (Order of pairs is unknown)
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('a', 2); bmap.insert('b', 3); assert_eq!(bmap.flat_collect(), [('a',1), ('a',2), ('b',3)]);
fn insert(&self, k: L, v: R)
[src]
Inserts the given key-value pair into the BisetMap
.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('a', 1); bmap.insert('a', 2); bmap.insert('b', 3); assert_eq!(bmap.flat_collect(), [('a',1), ('a',2), ('b',3)]);
fn remove(&self, k: &L, v: &R)
[src]
Removes the specified key-value pair from the BisetMap
.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('a', 1); bmap.insert('a', 2); bmap.insert('c', 3); assert_eq!(bmap.len(), 2); assert_eq!(bmap.rev_len(), 3); bmap.remove(&'a', &2); assert_eq!(bmap.len(), 2); assert_eq!(bmap.rev_len(), 2);
fn contains(&self, k: &L, v: &R) -> bool
[src]
Returns true
if the map contains the given key-value pair and false
otherwise.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); assert!(bmap.contains(&'a', &1)); assert!(!bmap.contains(&'b', &1)); assert!(!bmap.contains(&'a', &2));
fn key_exists(&self, k: &L) -> bool
[src]
Returns true
if the map contains the given key (left) value and false
otherwise.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); assert!(bmap.key_exists(&'a')); assert!(!bmap.key_exists(&'b'));
fn value_exists(&self, v: &R) -> bool
[src]
Returns true
if the map contains the given value (right) and false
otherwise.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); assert!(bmap.value_exists(&1)); assert!(!bmap.value_exists(&2));
fn get(&self, k: &L) -> Vec<R>
[src]
Returns a vector of values (right) corresponding to the given key (left).
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); assert_eq!(bmap.get(&'a'), [1]); assert_eq!(bmap.get(&'z'), []);
fn rev_get(&self, v: &R) -> Vec<L>
[src]
Returns a vector of keys (left) corresponding to the given value (right).
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); assert_eq!(bmap.rev_get(&1), ['a']); assert_eq!(bmap.rev_get(&2), []);
fn delete(&self, k: &L) -> Vec<R>
[src]
Removes the specified key and all values associated with it.
Returns a vector of previous values associated with given key.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('a', 2); bmap.insert('c', 3); assert_eq!(bmap.delete(&'a'), [1, 2]); assert_eq!(bmap.len(), 1);
fn rev_delete(&self, v: &R) -> Vec<L>
[src]
Removes the specified key and all values associated with it.
Returns a vector of previous keys associated with given value.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('b', 1); bmap.insert('c', 2); assert_eq!(bmap.rev_delete(&1), ['a', 'b']); assert_eq!(bmap.len(), 1);
fn len(&self) -> usize
[src]
Returns the number of unique keys (left).
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('b', 2); bmap.insert('c', 3); bmap.insert('c', 4); assert_eq!(bmap.len(), 3);
fn rev_len(&self) -> usize
[src]
Returns the number of unique values (right).
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); bmap.insert('a', 1); bmap.insert('b', 2); bmap.insert('c', 3); bmap.insert('d', 3); assert_eq!(bmap.rev_len(), 3);
fn is_empty(&self) -> bool
[src]
Returns true
if the map contains no key-value pairs, and false
otherwise.
Examples
use bisetmap::BisetMap; let bmap = BisetMap::new(); assert!(bmap.is_empty()); bmap.insert('a', 1); assert!(!bmap.is_empty()); bmap.rev_delete(&1); assert!(bmap.is_empty());
Trait Implementations
impl<L: Clone + Eq + Hash + Clone, R: Clone + Eq + Hash + Clone> Clone for BisetMap<L, R>
[src]
fn clone(&self) -> BisetMap<L, R>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more