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]

[src]

Creates an empty BisetMap.

Examples

use bisetmap::BisetMap;

let bmap: BisetMap<char, u32> = BisetMap::new();

[src]

Creates an empty BisetMap with the given capacity.

Examples

use bisetmap::BisetMap;

let bmap: BisetMap<char, u32> = BisetMap::with_capacity(5);

[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);

[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']);

[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])]);

[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)]);

[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)]);

[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);

[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));

[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'));

[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));

[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'), []);

[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), []);

[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);

[src]

Removes the specified value and all keys 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);

[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);

[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);

[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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<L: Eq + Hash + Clone, R: Eq + Hash + Clone> Default for BisetMap<L, R>
[src]

[src]

Returns the "default value" for a type. Read more

impl<L: Eq + Hash + Clone + Debug, R: Eq + Hash + Clone + Debug> Debug for BisetMap<L, R>
[src]

[src]

Formats the value using the given formatter.

impl<L: Eq + Hash + Clone + Serialize, R: Eq + Hash + Clone + Serialize> Serialize for BisetMap<L, R>
[src]

[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, L: Eq + Hash + Clone + Deserialize<'de>, R: Eq + Hash + Clone + Deserialize<'de>> Deserialize<'de> for BisetMap<L, R>
[src]

[src]

Deserialize this value from the given Serde deserializer. Read more