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>

source

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.

source

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>

source

pub fn with_hasher(hash_builder: S) -> Self

Creates an empty multimap which will use the given hash builder to hash keys.

source

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.

source

pub fn key_capacity(&self) -> usize

Returns the number of keys the multimap can hold without reallocating.

source

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

source

pub const fn is_empty(&self) -> bool

Returns true if the multimap contains no elements.

source

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

source

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

Reserve capacity for additional more keys.

source

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.

source

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.

source

pub fn get<Q>(&self, key: &Q) -> Option<&Vec<V>>
where Q: ?Sized + Hash + Equivalent<K>,

Return a reference to the vec_equivalent stored for key, if it is present, else None.

source

pub fn get_key_values<Q>(&self, key: &Q) -> Option<(&K, &Vec<V>)>
where Q: ?Sized + Hash + Equivalent<K>,

Return references to the key-values pair stored for key, if it is present, else None.

source

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

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

source

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

Insert the value into the multimap.

Allows duplicates.

source

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

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k, &v) returns false.

source

pub fn contains<Q, R>(&self, key: &Q, value: &R) -> bool
where Q: ?Sized + Hash + Equivalent<K>, R: ?Sized + Equivalent<V>,

Multimap specific methods Return true if an equivalent key and value combination exists in the multimap.

source

pub const fn as_map(&self) -> &IndexMap<K, Vec<V>, S>

Return a borrow of the underlying map.

source

pub fn into_map(self) -> IndexMap<K, Vec<V>, S>

Return the underlying map, the multimap cannot be used after calling this.

source

pub fn swap_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
where Q: ?Sized + Hash + Equivalent<K>,

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.

source

pub fn shift_remove_key<Q>(&mut self, key: &Q) -> Option<Vec<V>>
where Q: ?Sized + Hash + Equivalent<K>,

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.

source

pub fn swap_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
where Q: ?Sized + Hash + Equivalent<K>,

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.

source

pub fn shift_remove_key_entry<Q>(&mut self, key: &Q) -> Option<(K, Vec<V>)>
where Q: ?Sized + Hash + Equivalent<K>,

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.

source

pub fn swap_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
where Q: ?Sized + Hash + Equivalent<K>, R: ?Sized + Equivalent<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!

source

pub fn shift_remove<Q, R>(&mut self, key: &Q, value: &R) -> Option<V>
where Q: ?Sized + Hash + Equivalent<K>, R: ?Sized + Equivalent<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!

source

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)

source

pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &Vec<V>)>
where Q: ?Sized + Hash + Equivalent<K>,

Return item index, key, and values.

source

pub fn get_key_index<Q>(&self, key: &Q) -> Option<usize>
where Q: ?Sized + Hash + Equivalent<K>,

Return key index if it exists in the map.

source

pub fn get_index(&self, index: usize) -> Option<(&K, &Vec<V>)>

Get a key-value pair by index, if it is present, else None.

source§

impl<K, V, S> IndexVecMultimap<K, V, S>

source

pub fn iter(&self) -> Iter<'_, K, V>

Return an iterator over the key-value pairs of the multimap.

source

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

Return an iterator over the values of the multimap.

source§

impl<K, V, S> IndexVecMultimap<K, V, S>

source

pub fn keys(&self) -> Keys<'_, K, V>

Return an iterator over the keys of the multimap.

source§

impl<K, V, S> IndexVecMultimap<K, V, S>

source

pub fn into_values(self) -> IntoValues<K, V>

Return an iterator over the values of the multimap.

source§

impl<K, V, S> IndexVecMultimap<K, V, S>

source

pub fn into_keys(self) -> IntoKeys<K, V>

Return an owning iterator over the keys of the multimap.

Trait Implementations§

source§

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

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug, S: Debug> Debug for IndexVecMultimap<K, V, S>

source§

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

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

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

source§

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

source§

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

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

source§

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

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> From<IndexMap<K, Vec<V>, S>> for IndexVecMultimap<K, V, S>
where K: Hash + Eq, V: Eq, S: BuildHasher + Default,

source§

fn from(map: IndexMap<K, Vec<V>, S>) -> Self

Converts to this type from the input type.
source§

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

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iterable: I) -> Self

Creates a value from an iterator. Read more
source§

impl<K, Q, V, S> Index<&Q> for IndexVecMultimap<K, V, S>
where K: Hash + Eq, Q: Hash + Equivalent<K> + ?Sized, V: Eq, S: BuildHasher + Default,

source§

fn index(&self, key: &Q) -> &Vec<V>

Returns a reference to the values container corresponding to the supplied key.

§Panics

Panics if the key is not present in the multimap.

§

type Output = Vec<V>

The returned type after indexing.
source§

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

§

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

Which kind of iterator are we turning this into?
§

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

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V, S> IntoIterator for IndexVecMultimap<K, V, S>
where K: Clone,

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V1, S1, V2, S2> PartialEq<IndexVecMultimap<K, V2, S2>> for IndexVecMultimap<K, V1, S1>
where K: Hash + Eq, V1: Eq + PartialEq<V2> + Borrow<V2>, V2: Eq + PartialEq<V1> + Borrow<V1>, S1: BuildHasher + Default, S2: BuildHasher + Default,

source§

fn eq(&self, other: &IndexVecMultimap<K, V2, S2>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V, S> Eq for IndexVecMultimap<K, V, S>
where K: Eq + Hash, V: Eq, S: BuildHasher + Default,

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

§

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

§

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

§

impl<K, V, S> UnwindSafe for IndexVecMultimap<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.