pub struct FlatMultimap<K, V, S = RandomState> { /* private fields */ }
Expand description
Multimap implementation where entries are stored as a flattened hash map.
§Examples
use flat_multimap::FlatMultimap;
let mut map = FlatMultimap::new();
map.insert(1, 1);
map.insert(1, 2);
map.insert(2, 3);
assert_eq!(map.len(), 3);
Implementations§
Source§impl<K, V> FlatMultimap<K, V, RandomState>
impl<K, V> FlatMultimap<K, V, RandomState>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty FlatMultimap
with a capacity of 0,
so it will not allocate until it is first inserted into.
§Examples
use flat_multimap::FlatMultimap;
let mut map: FlatMultimap<&str, i32> = FlatMultimap::new();
assert_eq!(map.capacity(), 0);
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty FlatMultimap
with at least the specified capacity.
Source§impl<K, V, S> FlatMultimap<K, V, S>
impl<K, V, S> FlatMultimap<K, V, S>
Sourcepub const fn with_hasher(hash_builder: S) -> Self
pub const fn with_hasher(hash_builder: S) -> Self
Creates an empty FlatMultimap
with default capacity which will use the given hash builder to hash keys.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates an empty FlatMultimap
with at least the specified capacity, using the given hash builder to hash keys.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
Sourcepub const fn hasher(&self) -> &S
pub const fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
Sourcepub fn drain(&mut self) -> Drain<'_, K, V> ⓘ
pub fn drain(&mut self) -> Drain<'_, K, V> ⓘ
Clears the map, returning all key-value pairs as an iterator.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a K, &'a V)
.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is (&’a K, &’a mut V).
Sourcepub fn keys(&self) -> Keys<'_, K, V> ⓘ
pub fn keys(&self) -> Keys<'_, K, V> ⓘ
An iterator visiting all keys in arbitrary order. The iterator element type is &'a K
.
§Examples
use flat_multimap::FlatMultimap;
let mut map = FlatMultimap::new();
map.insert(1, 1);
map.insert(1, 2);
map.insert(2, 3);
let mut keys: Vec<_> = map.keys().collect();
keys.sort_unstable(); // Sort since the keys are visited in arbitrary order.
assert_eq!(keys, [&1, &1, &2]);
Sourcepub fn into_keys(self) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V> ⓘ
Creates a consuming iterator visiting all the keys in arbitrary order.
The map cannot be used after calling this. The iterator element type is K
.
Sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
An iterator visiting all values in arbitrary order. The iterator element type is &'a V
.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
An iterator visiting all values mutably in arbitrary order. The iterator element type is &'a mut V
.
Sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
Creates a consuming iterator visiting all the values in arbitrary order.
The map cannot be used after calling this. The iterator element type is V
.
Source§impl<K, V, S> FlatMultimap<K, V, S>
impl<K, V, S> FlatMultimap<K, V, S>
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the FlatMultimap
.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional more elements to be inserted in the FlatMultimap
.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes an arbitrary value with the given key from the map, returning the removed value if there was a value at the key.
§Examples
use flat_multimap::FlatMultimap;
let mut map = FlatMultimap::new();
map.insert(1, 1);
map.insert(1, 2);
assert!(map.remove(&1).is_some()); // Could be either Some(1) or Some(2).
assert!(map.remove(&1).is_some()); // Could be either Some(1) or Some(2), depending on the previous remove.
assert!(map.remove(&1).is_none());
Source§impl<K: Sync, V: Sync, S> FlatMultimap<K, V, S>
impl<K: Sync, V: Sync, S> FlatMultimap<K, V, S>
Source§impl<K: Send, V: Send, S> FlatMultimap<K, V, S>
impl<K: Send, V: Send, S> FlatMultimap<K, V, S>
Sourcepub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V>
pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V>
Visits (potentially in parallel) mutably borrowed values in an arbitrary order.
Trait Implementations§
Source§impl<K: Clone, V: Clone, S: Clone> Clone for FlatMultimap<K, V, S>
impl<K: Clone, V: Clone, S: Clone> Clone for FlatMultimap<K, V, S>
Source§fn clone(&self) -> FlatMultimap<K, V, S>
fn clone(&self) -> FlatMultimap<K, V, S>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<K, V, S> Debug for FlatMultimap<K, V, S>
impl<K, V, S> Debug for FlatMultimap<K, V, S>
Source§impl<K, V, S> Default for FlatMultimap<K, V, S>where
S: Default,
impl<K, V, S> Default for FlatMultimap<K, V, S>where
S: Default,
Source§impl<'de, K, V, S> Deserialize<'de> for FlatMultimap<K, V, S>
impl<'de, K, V, S> Deserialize<'de> for FlatMultimap<K, V, S>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a, K, V, S> Extend<&'a (K, V)> for FlatMultimap<K, V, S>
impl<'a, K, V, S> Extend<&'a (K, V)> for FlatMultimap<K, V, S>
Source§fn extend<T: IntoIterator<Item = &'a (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a (K, V)>>(&mut self, iter: T)
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<'a, K, V, S> Extend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
Source§fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
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 FlatMultimap<K, V, S>
impl<K, V, S> Extend<(K, V)> for FlatMultimap<K, V, S>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
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, const N: usize> From<[(K, V); N]> for FlatMultimap<K, V, RandomState>
impl<K, V, const N: usize> From<[(K, V); N]> for FlatMultimap<K, V, RandomState>
Source§impl<K, V, S> FromIterator<(K, V)> for FlatMultimap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for FlatMultimap<K, V, S>
Source§impl<K, V, S> FromParallelIterator<(K, V)> for FlatMultimap<K, V, S>
impl<K, V, S> FromParallelIterator<(K, V)> for FlatMultimap<K, V, S>
Source§fn from_par_iter<P>(par_iter: P) -> Selfwhere
P: IntoParallelIterator<Item = (K, V)>,
fn from_par_iter<P>(par_iter: P) -> Selfwhere
P: IntoParallelIterator<Item = (K, V)>,
par_iter
. Read moreSource§impl<'a, K, V, S> IntoIterator for &'a FlatMultimap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a FlatMultimap<K, V, S>
Source§impl<'a, K, V, S> IntoIterator for &'a mut FlatMultimap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a mut FlatMultimap<K, V, S>
Source§impl<K, V, S> IntoIterator for FlatMultimap<K, V, S>
impl<K, V, S> IntoIterator for FlatMultimap<K, V, S>
Source§impl<'a, K: Sync, V: Sync, S> IntoParallelIterator for &'a FlatMultimap<K, V, S>
impl<'a, K: Sync, V: Sync, S> IntoParallelIterator for &'a FlatMultimap<K, V, S>
Source§impl<'a, K: Sync, V: Send, S> IntoParallelIterator for &'a mut FlatMultimap<K, V, S>
impl<'a, K: Sync, V: Send, S> IntoParallelIterator for &'a mut FlatMultimap<K, V, S>
Source§impl<K: Send, V: Send, S> IntoParallelIterator for FlatMultimap<K, V, S>
impl<K: Send, V: Send, S> IntoParallelIterator for FlatMultimap<K, V, S>
Source§impl<'a, K, V, S> ParallelExtend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
impl<'a, K, V, S> ParallelExtend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
Source§fn par_extend<I>(&mut self, par_iter: I)
fn par_extend<I>(&mut self, par_iter: I)
par_iter
. Read moreSource§impl<K, V, S> ParallelExtend<(K, V)> for FlatMultimap<K, V, S>
impl<K, V, S> ParallelExtend<(K, V)> for FlatMultimap<K, V, S>
Source§fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = (K, V)>,
fn par_extend<I>(&mut self, par_iter: I)where
I: IntoParallelIterator<Item = (K, V)>,
par_iter
. Read moreAuto Trait Implementations§
impl<K, V, S> Freeze for FlatMultimap<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for FlatMultimap<K, V, S>
impl<K, V, S> Send for FlatMultimap<K, V, S>
impl<K, V, S> Sync for FlatMultimap<K, V, S>
impl<K, V, S> Unpin for FlatMultimap<K, V, S>
impl<K, V, S> UnwindSafe for FlatMultimap<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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<'data, I> IntoParallelRefIterator<'data> for I
impl<'data, I> IntoParallelRefIterator<'data> for I
Source§impl<'data, I> IntoParallelRefMutIterator<'data> for I
impl<'data, I> IntoParallelRefMutIterator<'data> for I
Source§type Iter = <&'data mut I as IntoParallelIterator>::Iter
type Iter = <&'data mut I as IntoParallelIterator>::Iter
Source§type Item = <&'data mut I as IntoParallelIterator>::Item
type Item = <&'data mut I as IntoParallelIterator>::Item
&'data mut T
reference.Source§fn par_iter_mut(
&'data mut self,
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
fn par_iter_mut( &'data mut self, ) -> <I as IntoParallelRefMutIterator<'data>>::Iter
self
. Read more