Struct multimap::MultiMap[][src]

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

Implementations

Creates an empty MultiMap

Examples
use multimap::MultiMap;

let mut map: MultiMap<&str, isize> = MultiMap::new();

Creates an empty multimap with the given initial capacity.

Examples
use multimap::MultiMap;

let mut map: MultiMap<&str, isize> = MultiMap::with_capacity(20);

Creates an empty MultiMap which will use the given hash builder to hash keys.

Examples
use multimap::MultiMap;
use std::collections::hash_map::RandomState;

let s = RandomState::new();
let mut map: MultiMap<&str, isize> = MultiMap::with_hasher(s);

Creates an empty MultiMap with the given intial capacity and hash builder.

Examples
use multimap::MultiMap;
use std::collections::hash_map::RandomState;

let s = RandomState::new();
let mut map: MultiMap<&str, isize> = MultiMap::with_capacity_and_hasher(20, s);

Inserts a key-value pair into the multimap. If the key does exist in the map then the value is pushed to that key’s vector. If the key doesn’t exist in the map a new vector with the given value is inserted.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert("key", 42);

Inserts multiple key-value pairs into the multimap. If the key does exist in the map then the values are extended into that key’s vector. If the key doesn’t exist in the map a new vector collected from the given values is inserted.

This may be more efficient than inserting values independently.

Examples
use multimap::MultiMap;

let mut map = MultiMap::<&str, &usize>::new();
map.insert_many("key", &[42, 43]);

Inserts multiple key-value pairs into the multimap. If the key does exist in the map then the values are extended into that key’s vector. If the key doesn’t exist in the map a new vector collected from the given values is inserted.

This may be more efficient than inserting values independently.

Examples
use multimap::MultiMap;

let mut map = MultiMap::<&str, usize>::new();
map.insert_many_from_slice("key", &[42, 43]);

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);

Returns the number of elements in the map.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(2, 1337);
assert_eq!(map.len(), 2);

Removes a key from the map, returning the vector of values at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
assert_eq!(map.remove(&1), Some(vec![42, 1337]));
assert_eq!(map.remove(&1), None);

Returns a reference to the first item in the vector corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
assert_eq!(map.get(&1), Some(&42));

Returns a mutable reference to the first item in the vector corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
if let Some(v) = map.get_mut(&1) {
    *v = 99;
}
assert_eq!(map[&1], 99);

Returns a reference to the vector corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
assert_eq!(map.get_vec(&1), Some(&vec![42, 1337]));

Returns a mutable reference to the vector corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
if let Some(v) = map.get_vec_mut(&1) {
    (*v)[0] = 1991;
    (*v)[1] = 2332;
}
assert_eq!(map.get_vec(&1), Some(&vec![1991, 2332]));

Returns true if the key is multi-valued.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1, 42);
map.insert(1, 1337);
map.insert(2, 2332);

assert_eq!(map.is_vec(&1), true);   // key is multi-valued
assert_eq!(map.is_vec(&2), false);  // key is single-valued
assert_eq!(map.is_vec(&3), false);  // key not in map

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

Examples
use multimap::MultiMap;

let map: MultiMap<usize, usize> = MultiMap::new();
assert!(map.capacity() >= 0);

Returns true if the map contains no elements.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
assert!(map.is_empty());
map.insert(1,42);
assert!(!map.is_empty());

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.clear();
assert!(map.is_empty());

An iterator visiting all keys in arbitrary order. Iterator element type is &’a K.

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.insert(2,1337);
map.insert(4,1991);

for key in map.keys() {
    println!("{:?}", key);
}

An iterator visiting all key-value pairs in arbitrary order. The iterator returns a reference to the key and the first element in the corresponding key’s vector. Iterator element type is (&’a K, &’a V).

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.insert(1,1337);
map.insert(3,2332);
map.insert(4,1991);

for (key, value) in map.iter() {
    println!("key: {:?}, val: {:?}", key, value);
}

An iterator visiting all key-value pairs in arbitrary order. The iterator returns a reference to the key and a mutable reference to the first element in the corresponding key’s vector. Iterator element type is (&’a K, &’a mut V).

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.insert(1,1337);
map.insert(3,2332);
map.insert(4,1991);

for (_, value) in map.iter_mut() {
    *value *= *value;
}

for (key, value) in map.iter() {
    println!("key: {:?}, val: {:?}", key, value);
}

An iterator visiting all key-value pairs in arbitrary order. The iterator returns a reference to the key and the corresponding key’s vector. Iterator element type is (&’a K, &’a V).

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.insert(1,1337);
map.insert(3,2332);
map.insert(4,1991);

for (key, values) in map.iter_all() {
    println!("key: {:?}, values: {:?}", key, values);
}

An iterator visiting all key-value pairs in arbitrary order. The iterator returns a reference to the key and the corresponding key’s vector. Iterator element type is (&’a K, &’a V).

Examples
use multimap::MultiMap;

let mut map = MultiMap::new();
map.insert(1,42);
map.insert(1,1337);
map.insert(3,2332);
map.insert(4,1991);

for (key, values) in map.iter_all_mut() {
    for value in values.iter_mut() {
        *value = 99;
    }
}

for (key, values) in map.iter_all() {
    println!("key: {:?}, values: {:?}", key, values);
}

Gets the specified key’s corresponding entry in the map for in-place manipulation. It’s possible to both manipulate the vector and the ‘value’ (the first value in the vector).

Examples
use multimap::MultiMap;

let mut m = MultiMap::new();
m.insert(1, 42);

{
    let mut v = m.entry(1).or_insert(43);
    assert_eq!(v, &42);
    *v = 44;
}
assert_eq!(m.entry(2).or_insert(666), &666);

{
    let mut v = m.entry(1).or_insert_vec(vec![43]);
    assert_eq!(v, &vec![44]);
    v.push(50);
}
assert_eq!(m.entry(2).or_insert_vec(vec![666]), &vec![666]);

assert_eq!(m.get_vec(&1), Some(&vec![44, 50]));

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k,&mut v) returns false.

Examples
use multimap::MultiMap;

let mut m = MultiMap::new();
m.insert(1, 42);
m.insert(1, 99);
m.insert(2, 42);
m.retain(|&k, &v| { k == 1 && v == 42 });
assert_eq!(1, m.len());
assert_eq!(Some(&42), m.get(&1));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.