pub struct HashSetMultimap<K, V, S = RandomState> { /* private fields */ }
Expand description
Multimap implementation that behaves like HashMap<K, HashSet<V>>
.
Implementations§
source§impl<K, V> HashSetMultimap<K, V, RandomState>
impl<K, V> HashSetMultimap<K, V, RandomState>
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> HashSetMultimap<K, V, S>
impl<K, V, S> HashSetMultimap<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> HashSetMultimap<K, V, S>
impl<K, V, S> HashSetMultimap<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<&HashSet<V, S>>
pub fn get<Q>(&self, key: &Q) -> Option<&HashSet<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, &HashSet<V, S>)>
pub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &HashSet<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) -> &HashMap<K, HashSet<V, S>, S>
pub const fn as_map(&self) -> &HashMap<K, HashSet<V, S>, S>
Return a borrow of the underlying map.
sourcepub fn into_map(self) -> HashMap<K, HashSet<V, S>, S>
pub fn into_map(self) -> HashMap<K, HashSet<V, S>, S>
Return the underlying map, the multimap cannot be used after calling this.
sourcepub fn remove_key<Q>(&mut self, key: &Q) -> Option<HashSet<V, S>>
pub fn remove_key<Q>(&mut self, key: &Q) -> Option<HashSet<V, S>>
Remove the key and all associated values from the multimap.
Returns values if at least one value is associated to key
,
returns None
otherwise.
sourcepub fn remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, HashSet<V, S>)>
pub fn remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, HashSet<V, S>)>
Removes the key and all associated values from the multimap.
Returns the entry (key and all associated values) if at least one
value is associated to key
, returns None
otherwise.
source§impl<K, V, S> HashSetMultimap<K, V, S>
impl<K, V, S> HashSetMultimap<K, V, S>
source§impl<K, V, S> HashSetMultimap<K, V, S>
impl<K, V, S> HashSetMultimap<K, V, S>
source§impl<K, V, S> HashSetMultimap<K, V, S>
impl<K, V, S> HashSetMultimap<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 HashSetMultimap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for HashSetMultimap<K, V, S>
source§fn clone(&self) -> HashSetMultimap<K, V, S>
fn clone(&self) -> HashSetMultimap<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 HashSetMultimap<K, V, S>where
S: Default,
impl<K, V, S> Default for HashSetMultimap<K, V, S>where
S: Default,
source§fn default() -> HashSetMultimap<K, V, S>
fn default() -> HashSetMultimap<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 HashSetMultimap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashSetMultimap<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 HashSetMultimap<K, V, S>
impl<K, V, S> Extend<(K, V)> for HashSetMultimap<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 HashSetMultimap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for HashSetMultimap<K, V, S>
source§impl<K, Q, V, S> Index<&Q> for HashSetMultimap<K, V, S>
impl<K, Q, V, S> Index<&Q> for HashSetMultimap<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a HashSetMultimap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a HashSetMultimap<K, V, S>
source§impl<K, V, S> IntoIterator for HashSetMultimap<K, V, S>where
K: Clone,
impl<K, V, S> IntoIterator for HashSetMultimap<K, V, S>where
K: Clone,
source§impl<K, V1, S1, V2, S2> PartialEq<HashSetMultimap<K, V2, S2>> for HashSetMultimap<K, V1, S1>
impl<K, V1, S1, V2, S2> PartialEq<HashSetMultimap<K, V2, S2>> for HashSetMultimap<K, V1, S1>
source§fn eq(&self, other: &HashSetMultimap<K, V2, S2>) -> bool
fn eq(&self, other: &HashSetMultimap<K, V2, S2>) -> bool
self
and other
values to be equal, and is used
by ==
.impl<K, V, S> Eq for HashSetMultimap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for HashSetMultimap<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for HashSetMultimap<K, V, S>
impl<K, V, S> Send for HashSetMultimap<K, V, S>
impl<K, V, S> Sync for HashSetMultimap<K, V, S>
impl<K, V, S> Unpin for HashSetMultimap<K, V, S>
impl<K, V, S> UnwindSafe for HashSetMultimap<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.