Struct more_collections::IndexVecMultimap
source · pub struct IndexVecMultimap<K, V, S = RandomState> { /* private fields */ }
Expand description
Multimap implementation that behaves like IndexMap<K, Vec<V>>
.
Implementations§
source§impl<K, V> IndexVecMultimap<K, V>
impl<K, V> IndexVecMultimap<K, V>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty multimap.
The multimap is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
sourcepub fn with_key_capacity(capacity: usize) -> Self
pub fn with_key_capacity(capacity: usize) -> Self
Creates an empty multimap with the specified key capacity.
The multimap will be able to hold at least capacity
keys without
reallocating. If capacity
is 0, the multimap will not allocate.
source§impl<K, V, S> IndexVecMultimap<K, V, S>
impl<K, V, S> IndexVecMultimap<K, V, S>
sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty multimap which will use the given hash builder to hash keys.
sourcepub fn with_key_capacity_and_hasher(n: usize, hash_builder: S) -> Self
pub fn with_key_capacity_and_hasher(n: usize, hash_builder: S) -> Self
Creates an empty multimap with the specified capacity, using hash_builder
to hash the keys.
sourcepub fn key_capacity(&self) -> usize
pub fn key_capacity(&self) -> usize
Returns the number of keys the multimap can hold without reallocating.
sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements in the multimap.
Note that the number of elements in the multimap may not be the
same as the number of keys in the multimap. See
Self::keys_len()
.
sourcepub fn keys_len(&self) -> usize
pub fn keys_len(&self) -> usize
Returns the number of keys in the multimap.
Note that the number of keys in the multimap may not be the
same as the number of elements in the multimap. See
Self::len()
.
source§impl<K, V, S> IndexVecMultimap<K, V, S>
impl<K, V, S> IndexVecMultimap<K, V, S>
sourcepub fn shrink_keys_to_fit(&mut self)
pub fn shrink_keys_to_fit(&mut self)
Shrinks the capacity of the multimap’s keys as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
sourcepub fn shrink_values_to_fit(&mut self)
pub fn shrink_values_to_fit(&mut self)
Shrinks the capacity of the multimap’s values as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
sourcepub fn get<Q>(&self, key: &Q) -> Option<&Vec<V>>
pub fn get<Q>(&self, key: &Q) -> Option<&Vec<V>>
Return a reference to the vec_equivalent stored for key
, if it is present, else None
.
sourcepub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &Vec<V>)>
pub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &Vec<V>)>
Return references to the key-values pair stored for key
, if it is
present, else None
.
sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true
if the map contains a value for the specified key.
sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Insert the value into the multimap.
Allows duplicates.
sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v)
such that f(&k, &v)
returns false
.
sourcepub fn contains<Q, R>(&self, key: &Q, value: &R) -> bool
pub fn contains<Q, R>(&self, key: &Q, value: &R) -> bool
Multimap specific methods
Return true
if an equivalent key
and value
combination exists in
the multimap.
sourcepub fn into_map(self) -> IndexMap<K, Vec<V>, S>
pub fn into_map(self) -> IndexMap<K, Vec<V>, S>
Return the underlying map, the multimap cannot be used after calling this.
sourcepub fn swap_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
pub fn swap_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
Remove the key and all associated values from the multimap.
Like IndexMap::swap_remove
, the key is removed by swapping it
with the last element of the map and popping it off. This
perturbs the position of what used to be the last element!
Returns values if at least one value is associated to key
,
returns None
otherwise.
sourcepub fn shift_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
pub fn shift_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
Remove the key and all associated values from the multimap.
Like IndexMap::shift_remove
, the key is removed by shifting all
of the elements that follow it, preserving their relative order.
This perturbs the index of all of those elements!
Returns values if at least one value is associated to key
,
returns None
otherwise.
sourcepub fn swap_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
pub fn swap_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
Removes the key and all associated values from the multimap.
Like IndexMap::swap_remove
, the key is removed by swapping it
with the last element of the map and popping it off. This
perturbs the position of what used to be the last element!
Returns the entry (key and all associated values) if at least one
value is associated to key
, returns None
otherwise.
sourcepub fn shift_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
pub fn shift_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
Removes the key and all associated values from the multimap.
Like IndexMap::shift_remove
, the key is removed by shifting all
of the elements that follow it, preserving their relative order.
This perturbs the index of all of those elements!
Returns the entry (key and all associated values) if at least one
value is associated to key
, returns None
otherwise.
sourcepub fn swap_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
pub fn swap_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
Remove the entry from the multimap, and return it if it was present.
Like IndexMap::swap_remove
, the pair is removed by swapping it
with the last element of the map and popping it off. This
perturbs the position of what used to be the last element!
sourcepub fn shift_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
pub fn shift_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
Remove the entry from the multimap, and return it if it was present.
Like IndexMap::shift_remove
, the pair is removed by shifting all
of the elements that follow it, preserving their relative order.
This perturbs the index of all of those elements!
sourcepub fn insert_full(&mut self, key: K, value: V) -> (usize, usize)
pub fn insert_full(&mut self, key: K, value: V) -> (usize, usize)
Insert a key-value pair in the multimap, and get its indices.
If an equivalent key already exists in the multimap, the key remains and retains its place in the order. If no equivalent key existed in the multimap the new key is inserted last in order.
The value is inserted last in order in the values for this particular key (duplicates are allowed).
Returns (key index, values index)
sourcepub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &Vec<V>)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &Vec<V>)>
Return item index, key, and values.
sourcepub fn get_key_index<Q>(&self, key: &Q) -> Option<usize>
pub fn get_key_index<Q>(&self, key: &Q) -> Option<usize>
Return key index if it exists in the map.
source§impl<K, V, S> IndexVecMultimap<K, V, S>
impl<K, V, S> IndexVecMultimap<K, V, S>
source§impl<K, V, S> IndexVecMultimap<K, V, S>
impl<K, V, S> IndexVecMultimap<K, V, S>
source§impl<K, V, S> IndexVecMultimap<K, V, S>
impl<K, V, S> IndexVecMultimap<K, V, S>
sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
Return an iterator over the values of the multimap.
Trait Implementations§
source§impl<K: Clone, V: Clone, S: Clone> Clone for IndexVecMultimap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for IndexVecMultimap<K, V, S>
source§fn clone(&self) -> IndexVecMultimap<K, V, S>
fn clone(&self) -> IndexVecMultimap<K, V, S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K, V, S> Default for IndexVecMultimap<K, V, S>where
S: Default,
impl<K, V, S> Default for IndexVecMultimap<K, V, S>where
S: Default,
source§fn default() -> IndexVecMultimap<K, V, S>
fn default() -> IndexVecMultimap<K, V, S>
Creates an empty multimap, with the Default
value for the hasher.
source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for IndexVecMultimap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for IndexVecMultimap<K, V, S>
source§fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iterable: I)
fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iterable: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<K, V, S> Extend<(K, V)> for IndexVecMultimap<K, V, S>
impl<K, V, S> Extend<(K, V)> for IndexVecMultimap<K, V, S>
source§fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iterable: I)
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iterable: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<K, V, S> FromIterator<(K, V)> for IndexVecMultimap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for IndexVecMultimap<K, V, S>
source§impl<K, Q, V, S> Index<&Q> for IndexVecMultimap<K, V, S>
impl<K, Q, V, S> Index<&Q> for IndexVecMultimap<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a IndexVecMultimap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a IndexVecMultimap<K, V, S>
source§impl<K, V, S> IntoIterator for IndexVecMultimap<K, V, S>where
K: Clone,
impl<K, V, S> IntoIterator for IndexVecMultimap<K, V, S>where
K: Clone,
source§impl<K, V1, S1, V2, S2> PartialEq<IndexVecMultimap<K, V2, S2>> for IndexVecMultimap<K, V1, S1>
impl<K, V1, S1, V2, S2> PartialEq<IndexVecMultimap<K, V2, S2>> for IndexVecMultimap<K, V1, S1>
source§fn eq(&self, other: &IndexVecMultimap<K, V2, S2>) -> bool
fn eq(&self, other: &IndexVecMultimap<K, V2, S2>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<K, V, S> Eq for IndexVecMultimap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for IndexVecMultimap<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for IndexVecMultimap<K, V, S>
impl<K, V, S> Send for IndexVecMultimap<K, V, S>
impl<K, V, S> Sync for IndexVecMultimap<K, V, S>
impl<K, V, S> Unpin for IndexVecMultimap<K, V, S>
impl<K, V, S> UnwindSafe for IndexVecMultimap<K, V, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.