CollectingHashMap

Struct CollectingHashMap 

Source
pub struct CollectingHashMap<K, V, S = RandomState>
where K: Hash + Eq, S: BuildHasher,
{ /* private fields */ }
Expand description

A hashmap that stores a vec of values for each key

Implementations§

Source§

impl<K, V> CollectingHashMap<K, V, RandomState>
where K: Hash + Eq,

Source

pub fn new() -> CollectingHashMap<K, V, RandomState>

Creates a new CollectingHashMap with the default Hasher

Source

pub fn with_capacity(capacity: usize) -> CollectingHashMap<K, V, RandomState>

Creates a new CollectingHashMap with the given capacity

Source§

impl<K, V, S> CollectingHashMap<K, V, S>
where K: Hash + Eq, S: BuildHasher,

Source

pub fn with_hashmap(h: HashMap<K, Vec<V>, S>) -> CollectingHashMap<K, V, S>

Creates a new CollectingHashMap using the given HashMap for it’s backing storage

Source

pub fn insert(&mut self, k: K, v: V)

Inserts a value for the given key

If the key is already present, this will append the value to the key’s Vec<V>

Source

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

Retrieves a reference to a value for the given key

If there is at least one value for the given key, this will return &V using the first element of Ks Vec<V>

Source

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

Retrieves a mutable reference to a value for the given key

If there is at least one value for the given key, this will return &mut V using the first element of Ks Vec<V>

Source

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

Retrieves a reference to all values stored for the given key

If there is at least one value present for the given key, this will return a reference to the Vec<V> for the key

Source

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

Retrieves a mutable reference to all values stored for the given key

If there is at least one value present for the given key, this will return a mutable reference to the Vec<V> for the key

Source

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

Removes a set of values for the given key

If there is a value present for the given key, this will remove all values from the underlying HashMap but will ONLY return the first element. To return the entire Vec<V> for the key, use remove_all

Source

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

Removes a set of values for the given key

If there is a value present for the given key, this will remove all values from the underlying HashMap, and return the Vec<V>

Source

pub fn hasher(&self) -> &S

The same as HashMap::hasher

Source

pub fn capacity(&self) -> usize

The same as HashMap::capacity

Source

pub fn is_empty(&self) -> bool

The same as HashMap::is_empty

Source

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

The same as HashMap::reserve

Source

pub fn shrink_to_fit(&mut self)

Source

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

The same as HashMap::keys

Source

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

The same as HashMap::values

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, Vec<V>>

The same as HashMap::values_mut

Source

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

The same as HashMap::iter

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, Vec<V>>

The same as HashMap::iter_mut

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, Vec<V>>

The same as HashMap::entry

Source

pub fn len(&self) -> usize

The same as HashMap::len

Source

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

The same as HashMap::drain

Source

pub fn clear(&mut self)

The same as HashMap::clear

Source

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

Source

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

Source

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

The same as HashMap::retain

Trait Implementations§

Source§

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

Source§

fn default() -> CollectingHashMap<K, V, S>

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

impl<K, V, S> Extend<(K, V)> for CollectingHashMap<K, V, S>
where K: Hash + Eq, 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, S> FromIterator<(K, V)> for CollectingHashMap<K, V, S>
where K: Hash + Eq, S: BuildHasher + Default,

Source§

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

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<K, V, S> Freeze for CollectingHashMap<K, V, S>
where S: Freeze,

§

impl<K, V, S> RefUnwindSafe for CollectingHashMap<K, V, S>

§

impl<K, V, S> Send for CollectingHashMap<K, V, S>
where K: Send, V: Send, S: Send,

§

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

§

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

§

impl<K, V, S> UnwindSafe for CollectingHashMap<K, V, S>
where K: UnwindSafe, S: 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> 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, 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.