pub struct MultiMap<K1: Eq + Hash, K2: Eq + Hash, V> { /* fields omitted */ }
Creates a new MultiMap. The primary key is of type K1
and the
secondary key is of type K2
. The value is of type V
. This is as
compared to a std::collections::HashMap
which is typed on just K
and
V
.
Internally, two HashMaps are created - a main one on <K1, (K2, V)>
and a second one on <K2, K1>
. The (K2, V)
tuple is so
that when an item is removed using the K1
key, the appropriate K2
value is available so the K2->K1
map can be removed from the second
HashMap, to keep them in sync.
Creates an empty MultiMap with the specified capacity.
The multi map will be able to hold at least capacity
elements without reallocating. If capacity
is 0, the multi map will not allocate.
pub fn insert(&mut self, key_one: K1, key_two: K2, value: V) | [src] |
Insert an item into the MultiMap. You must supply both keys to insert
an item. The keys cannot be modified at a later date, so if you only
have one key at this time, use a placeholder value for the second key
(perhaps K2
is Option<...>
) and remove then re-insert when the
second key becomes available.
Obtain a reference to an item in the MultiMap using the primary key,
just like a HashMap.
Obtain a mutable reference to an item in the MultiMap using the
primary key, just like a HashMap.
Obtain a reference to an item in the MultiMap using the secondary key.
Ordinary HashMaps can't do this.
Obtain a mutable reference to an item in the MultiMap using the
secondary key. Ordinary HashMaps can't do this.
Remove an item from the HashMap using the primary key. The value for the
given key is returned (if it exists), just like a HashMap. This removes
an item from the main HashMap, and the second <K2, K1>
HashMap.
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
#[macro_use]
extern crate multi_map;
use multi_map::MultiMap;
let map = multimap! {
1, "One" => String::from("Eins"),
2, "Two" => String::from("Zwei"),
3, "Three" => String::from("Drei"),
};
assert!(map.contains_key(&1));
assert!(!map.contains_key(&4));
Returns true if the map contains a value for the specified alternative 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
#[macro_use]
extern crate multi_map;
use multi_map::MultiMap;
let map = multimap! {
1, "One" => String::from("Eins"),
2, "Two" => String::from("Zwei"),
3, "Three" => String::from("Drei"),
};
assert!(map.contains_key_alt(&"One"));
assert!(!map.contains_key_alt(&"Four"));
Remove an item from the HashMap using the secondary key. The value for
the given key is returned (if it exists). Ordinary HashMaps can't do
this. This removes an item from both the main HashMap and the second
<K2, K1>
HashMap.
Iterate through all the values in the MultiMap. Note that the values
are (K2, V)
tuples, not V
, as you would get with a HashMap.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)