Struct FlatMultimap

Source
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>

Source

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);
Source

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>

Source

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.

Source

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.

Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

Source

pub const fn hasher(&self) -> &S

Returns a reference to the map’s BuildHasher.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Clears the map, returning all key-value pairs as an iterator.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

Retains only the elements specified by the predicate.

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Source

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).

Source

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).

Source

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]);
Source

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.

Source

pub fn values(&self) -> Values<'_, K, V>

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

Source

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.

Source

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>
where K: Eq + Hash, S: BuildHasher,

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the FlatMultimap.

Source

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.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the map with a lower limit.

Source

pub fn insert(&mut self, key: K, value: V)

Inserts a key-value pair into the map.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

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

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns true if the map contains at least a single value for the specified key.

Source§

impl<K: Sync, V: Sync, S> FlatMultimap<K, V, S>

Source

pub fn par_keys(&self) -> ParKeys<'_, K, V>

Visits (potentially in parallel) immutably borrowed keys in an arbitrary order.

Source

pub fn par_values(&self) -> ParValues<'_, K, V>

Visits (potentially in parallel) immutably borrowed values in an arbitrary order.

Source§

impl<K: Send, V: Send, S> FlatMultimap<K, V, S>

Source

pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V>

Visits (potentially in parallel) mutably borrowed values in an arbitrary order.

Source

pub fn par_drain(&mut self) -> ParDrain<'_, K, V>

Consumes (potentially in parallel) all values in an arbitrary order.

Trait Implementations§

Source§

impl<K: Clone, V: Clone, S: Clone> Clone for FlatMultimap<K, V, S>

Source§

fn clone(&self) -> FlatMultimap<K, V, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, S> Debug for FlatMultimap<K, V, S>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, S> Default for FlatMultimap<K, V, S>
where S: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, K, V, S> Deserialize<'de> for FlatMultimap<K, V, S>
where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>, S: BuildHasher + Default,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, K, V, S> Extend<&'a (K, V)> for FlatMultimap<K, V, S>
where K: Eq + Hash + Copy, V: Copy, S: BuildHasher,

Source§

fn extend<T: IntoIterator<Item = &'a (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
where K: Eq + Hash + Copy, V: Copy, S: BuildHasher,

Source§

fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K, V, S> Extend<(K, V)> for FlatMultimap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

Source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K, V, const N: usize> From<[(K, V); N]> for FlatMultimap<K, V, RandomState>
where K: Eq + Hash,

Source§

fn from(arr: [(K, V); N]) -> Self

Converts to this type from the input type.
Source§

impl<K, V, S> FromIterator<(K, V)> for FlatMultimap<K, V, S>
where K: Eq + Hash, S: BuildHasher + Default,

Source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<K, V, S> FromParallelIterator<(K, V)> for FlatMultimap<K, V, S>
where K: Eq + Hash + Send, V: Send, S: BuildHasher + Default,

Source§

fn from_par_iter<P>(par_iter: P) -> Self
where P: IntoParallelIterator<Item = (K, V)>,

Creates an instance of the collection from the parallel iterator par_iter. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a FlatMultimap<K, V, S>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a, K, V>

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a mut FlatMultimap<K, V, S>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IterMut<'a, K, V>

Creates an iterator from a value. Read more
Source§

impl<K, V, S> IntoIterator for FlatMultimap<K, V, S>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<K, V>

Creates an iterator from a value. Read more
Source§

impl<'a, K: Sync, V: Sync, S> IntoParallelIterator for &'a FlatMultimap<K, V, S>

Source§

type Item = (&'a K, &'a V)

The type of item that the parallel iterator will produce.
Source§

type Iter = ParIter<'a, K, V>

The parallel iterator type that will be created.
Source§

fn into_par_iter(self) -> Self::Iter

Converts self into a parallel iterator. Read more
Source§

impl<'a, K: Sync, V: Send, S> IntoParallelIterator for &'a mut FlatMultimap<K, V, S>

Source§

type Item = (&'a K, &'a mut V)

The type of item that the parallel iterator will produce.
Source§

type Iter = ParIterMut<'a, K, V>

The parallel iterator type that will be created.
Source§

fn into_par_iter(self) -> Self::Iter

Converts self into a parallel iterator. Read more
Source§

impl<K: Send, V: Send, S> IntoParallelIterator for FlatMultimap<K, V, S>

Source§

type Item = (K, V)

The type of item that the parallel iterator will produce.
Source§

type Iter = IntoParIter<K, V>

The parallel iterator type that will be created.
Source§

fn into_par_iter(self) -> Self::Iter

Converts self into a parallel iterator. Read more
Source§

impl<'a, K, V, S> ParallelExtend<(&'a K, &'a V)> for FlatMultimap<K, V, S>
where K: Copy + Eq + Hash + Sync, V: Copy + Sync, S: BuildHasher,

Source§

fn par_extend<I>(&mut self, par_iter: I)
where I: IntoParallelIterator<Item = (&'a K, &'a V)>,

Extends an instance of the collection with the elements drawn from the parallel iterator par_iter. Read more
Source§

impl<K, V, S> ParallelExtend<(K, V)> for FlatMultimap<K, V, S>
where K: Eq + Hash + Send, V: Send, S: BuildHasher,

Source§

fn par_extend<I>(&mut self, par_iter: I)
where I: IntoParallelIterator<Item = (K, V)>,

Extends an instance of the collection with the elements drawn from the parallel iterator par_iter. Read more
Source§

impl<K, V, H> Serialize for FlatMultimap<K, V, H>
where K: Serialize, V: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto 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>
where S: Send, K: Send, V: Send,

§

impl<K, V, S> Sync for FlatMultimap<K, V, S>
where S: Sync, K: Sync, V: Sync,

§

impl<K, V, S> Unpin for FlatMultimap<K, V, S>
where S: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, S> UnwindSafe for FlatMultimap<K, V, S>
where S: UnwindSafe, K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<'data, I> IntoParallelRefIterator<'data> for I
where I: 'data + ?Sized, &'data I: IntoParallelIterator,

Source§

type Iter = <&'data I as IntoParallelIterator>::Iter

The type of the parallel iterator that will be returned.
Source§

type Item = <&'data I as IntoParallelIterator>::Item

The type of item that the parallel iterator will produce. This will typically be an &'data T reference type.
Source§

fn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter

Converts self into a parallel iterator. Read more
Source§

impl<'data, I> IntoParallelRefMutIterator<'data> for I

Source§

type Iter = <&'data mut I as IntoParallelIterator>::Iter

The type of iterator that will be created.
Source§

type Item = <&'data mut I as IntoParallelIterator>::Item

The type of item that will be produced; this is typically an &'data mut T reference.
Source§

fn par_iter_mut( &'data mut self, ) -> <I as IntoParallelRefMutIterator<'data>>::Iter

Creates the parallel iterator from self. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,