pub struct IndexSetMultimap<K, V, S = RandomState> { /* private fields */ }
Expand description
Multimap implementation that behaves like IndexMap<K, IndexSet<V>>
.
Implementations§
source§impl<K, V> IndexSetMultimap<K, V>
impl<K, V> IndexSetMultimap<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> IndexSetMultimap<K, V, S>
impl<K, V, S> IndexSetMultimap<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> IndexSetMultimap<K, V, S>
impl<K, V, S> IndexSetMultimap<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<&IndexSet<V, S>>
pub fn get<Q>(&self, key: &Q) -> Option<&IndexSet<V, S>>
Return a reference to the set stored for key
, if it is present, else None
.
sourcepub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &IndexSet<V, S>)>
pub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &IndexSet<V, S>)>
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) -> bool
pub fn insert(&mut self, key: K, value: V) -> bool
Insert the value into the multimap.
If an equivalent entry already exists in the multimap, it returns
false
leaving the original value in the set and without altering its
insertion order. Otherwise, it inserts the new entry and returns true
.
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 const fn as_map(&self) -> &IndexMap<K, IndexSet<V, S>, S>
pub const fn as_map(&self) -> &IndexMap<K, IndexSet<V, S>, S>
Return a borrow of the underlying map.
sourcepub fn into_map(self) -> IndexMap<K, IndexSet<V, S>, S>
pub fn into_map(self) -> IndexMap<K, IndexSet<V, S>, S>
Return the underlying map, the multimap cannot be used after calling this.
sourcepub fn swap_remove_key<Q>(&mut self, key: &Q) -> Option<IndexSet<V, S>>
pub fn swap_remove_key<Q>(&mut self, key: &Q) -> Option<IndexSet<V, S>>
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<IndexSet<V, S>>
pub fn shift_remove_key<Q>(&mut self, key: &Q) -> Option<IndexSet<V, S>>
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, IndexSet<V, S>)>
pub fn swap_remove_key_entry<Q>( &mut self, key: &Q, ) -> Option<(K, IndexSet<V, S>)>
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, IndexSet<V, S>)>
pub fn shift_remove_key_entry<Q>( &mut self, key: &Q, ) -> Option<(K, IndexSet<V, S>)>
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, bool)
pub fn insert_full(&mut self, key: K, value: V) -> (usize, usize, bool)
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. Additionally, if an
equivalent value already exists for that particular key the value
remains and retains its place in the order, and false
is
returned.
If no equivalent key existed in the multimap the new key is inserted last in order. If no equivalent value existed in the multimap for this key, the value is inserted last in order.
Returns (key index, values index, success)
where success is
true
if the multimap changes as a result of calling this method.
sourcepub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &IndexSet<V, S>)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &IndexSet<V, S>)>
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> IndexSetMultimap<K, V, S>
impl<K, V, S> IndexSetMultimap<K, V, S>
source§impl<K, V, S> IndexSetMultimap<K, V, S>
impl<K, V, S> IndexSetMultimap<K, V, S>
source§impl<K, V, S> IndexSetMultimap<K, V, S>
impl<K, V, S> IndexSetMultimap<K, V, S>
sourcepub fn into_values(self) -> IntoValues<K, V, S> ⓘ
pub fn into_values(self) -> IntoValues<K, V, S> ⓘ
Return an iterator over the values of the multimap.
Trait Implementations§
source§impl<K: Clone, V: Clone, S: Clone> Clone for IndexSetMultimap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for IndexSetMultimap<K, V, S>
source§fn clone(&self) -> IndexSetMultimap<K, V, S>
fn clone(&self) -> IndexSetMultimap<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 IndexSetMultimap<K, V, S>where
S: Default,
impl<K, V, S> Default for IndexSetMultimap<K, V, S>where
S: Default,
source§fn default() -> IndexSetMultimap<K, V, S>
fn default() -> IndexSetMultimap<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 IndexSetMultimap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for IndexSetMultimap<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 IndexSetMultimap<K, V, S>
impl<K, V, S> Extend<(K, V)> for IndexSetMultimap<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 IndexSetMultimap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for IndexSetMultimap<K, V, S>
source§impl<K, Q, V, S> Index<&Q> for IndexSetMultimap<K, V, S>
impl<K, Q, V, S> Index<&Q> for IndexSetMultimap<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a IndexSetMultimap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a IndexSetMultimap<K, V, S>
source§impl<K, V, S> IntoIterator for IndexSetMultimap<K, V, S>where
K: Clone,
impl<K, V, S> IntoIterator for IndexSetMultimap<K, V, S>where
K: Clone,
source§impl<K, V1, S1, V2, S2> PartialEq<IndexSetMultimap<K, V2, S2>> for IndexSetMultimap<K, V1, S1>
impl<K, V1, S1, V2, S2> PartialEq<IndexSetMultimap<K, V2, S2>> for IndexSetMultimap<K, V1, S1>
source§fn eq(&self, other: &IndexSetMultimap<K, V2, S2>) -> bool
fn eq(&self, other: &IndexSetMultimap<K, V2, S2>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<K, V, S> Eq for IndexSetMultimap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for IndexSetMultimap<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for IndexSetMultimap<K, V, S>
impl<K, V, S> Send for IndexSetMultimap<K, V, S>
impl<K, V, S> Sync for IndexSetMultimap<K, V, S>
impl<K, V, S> Unpin for IndexSetMultimap<K, V, S>
impl<K, V, S> UnwindSafe for IndexSetMultimap<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.