[−][src]Struct multi_map::MultiMap
Methods
impl<K1: Eq + Hash + Clone, K2: Eq + Hash + Clone, V> MultiMap<K1, K2, V>
[src]
pub fn new() -> MultiMap<K1, K2, V>
[src]
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.
pub fn with_capacity(capacity: usize) -> MultiMap<K1, K2, V>
[src]
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.
pub fn get(&self, key: &K1) -> Option<&V>
[src]
Obtain a reference to an item in the MultiMap using the primary key, just like a HashMap.
pub fn get_mut(&mut self, key: &K1) -> Option<&mut V>
[src]
Obtain a mutable reference to an item in the MultiMap using the primary key, just like a HashMap.
pub fn get_alt(&self, key: &K2) -> Option<&V>
[src]
Obtain a reference to an item in the MultiMap using the secondary key. Ordinary HashMaps can't do this.
pub fn get_mut_alt(&mut self, key: &K2) -> Option<&mut V>
[src]
Obtain a mutable reference to an item in the MultiMap using the secondary key. Ordinary HashMaps can't do this.
pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
K1: Borrow<Q>,
Q: Hash + Eq,
[src]
K1: Borrow<Q>,
Q: Hash + Eq,
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.
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K1: Borrow<Q>,
Q: Hash + Eq,
[src]
K1: Borrow<Q>,
Q: Hash + Eq,
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
Example
#[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));
pub fn contains_key_alt<Q: ?Sized>(&self, key: &Q) -> bool where
K2: Borrow<Q>,
Q: Hash + Eq,
[src]
K2: Borrow<Q>,
Q: Hash + Eq,
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
Example
#[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"));
pub fn remove_alt<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
K2: Borrow<Q>,
Q: Hash + Eq,
[src]
K2: Borrow<Q>,
Q: Hash + Eq,
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.
pub fn iter(&self) -> Iter<K1, K2, V>
[src]
Iterate through all the values in the MultiMap in random order.
Note that the values
are (K2, V)
tuples, not V
, as you would get with a HashMap.
Trait Implementations
impl<K1: Eq + Hash + Debug, K2: Eq + Hash + Debug, V: Debug> Debug for MultiMap<K1, K2, V>
[src]
impl<K1, K2, V> Default for MultiMap<K1, K2, V> where
K1: Eq + Hash + Clone,
K2: Eq + Hash + Clone,
[src]
K1: Eq + Hash + Clone,
K2: Eq + Hash + Clone,
impl<K1: Eq + Hash, K2: Eq + Hash, V: Eq> Eq for MultiMap<K1, K2, V>
[src]
impl<K1, K2, V> IntoIterator for MultiMap<K1, K2, V> where
K1: Eq + Hash + Debug,
K2: Eq + Hash + Debug,
V: Debug,
[src]
K1: Eq + Hash + Debug,
K2: Eq + Hash + Debug,
V: Debug,
type Item = (K1, (K2, V))
The type of the elements being iterated over.
type IntoIter = IntoIter<K1, K2, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<K1, K2, V>
[src]
Creates a consuming iterator, that is, one that moves each key-value pair out of the map in arbitrary order. The map cannot be used after calling this.
impl<'a, K1, K2, V> IntoIterator for &'a MultiMap<K1, K2, V> where
K1: Eq + Hash + Debug + Clone,
K2: Eq + Hash + Debug + Clone,
V: Debug,
[src]
K1: Eq + Hash + Debug + Clone,
K2: Eq + Hash + Debug + Clone,
V: Debug,
type Item = (&'a K1, &'a (K2, V))
The type of the elements being iterated over.
type IntoIter = Iter<'a, K1, K2, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, K1, K2, V>
[src]
impl<K1: Eq + Hash, K2: Eq + Hash, V: Eq> PartialEq<MultiMap<K1, K2, V>> for MultiMap<K1, K2, V>
[src]
fn eq(&self, other: &MultiMap<K1, K2, V>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<K1: Eq + Hash, K2: Eq + Hash, V> StructuralEq for MultiMap<K1, K2, V>
[src]
Auto Trait Implementations
impl<K1, K2, V> RefUnwindSafe for MultiMap<K1, K2, V> where
K1: RefUnwindSafe,
K2: RefUnwindSafe,
V: RefUnwindSafe,
K1: RefUnwindSafe,
K2: RefUnwindSafe,
V: RefUnwindSafe,
impl<K1, K2, V> Send for MultiMap<K1, K2, V> where
K1: Send,
K2: Send,
V: Send,
K1: Send,
K2: Send,
V: Send,
impl<K1, K2, V> Sync for MultiMap<K1, K2, V> where
K1: Sync,
K2: Sync,
V: Sync,
K1: Sync,
K2: Sync,
V: Sync,
impl<K1, K2, V> Unpin for MultiMap<K1, K2, V> where
K1: Unpin,
K2: Unpin,
V: Unpin,
K1: Unpin,
K2: Unpin,
V: Unpin,
impl<K1, K2, V> UnwindSafe for MultiMap<K1, K2, V> where
K1: UnwindSafe,
K2: UnwindSafe,
V: UnwindSafe,
K1: UnwindSafe,
K2: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,