pub struct UnorderedHashMap<Key, Value, BH = RandomState>(/* private fields */);
Expand description

A hash map that does not care about the order of insertion. In particular, it does not support iterating, in order to guarantee deterministic compilation. It does support aggregation which can be used in intermediate computations (see aggregate_by). For an iterable version see OrderedHashMap.

Implementations§

source§

impl<Key, Value> UnorderedHashMap<Key, Value>

source

pub fn new() -> Self

source§

impl<Key, Value, BH> UnorderedHashMap<Key, Value, BH>

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§

impl<Key: Eq + Hash, Value, BH: BuildHasher> UnorderedHashMap<Key, Value, BH>

source

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

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

source

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

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

source

pub fn insert(&mut self, key: Key, value: Value) -> Option<Value>

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical.

source

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

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

source

pub fn entry(&mut self, key: Key) -> Entry<'_, Key, Value>

Gets the given key’s corresponding entry in the map for in-place manipulation.

source

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

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

source

pub fn aggregate_by<TargetKey: Eq + Hash, TargetValue>( &self, mapping_function: impl Fn(&Key) -> TargetKey, reduce_function: impl Fn(&TargetValue, &Value) -> TargetValue, default_value: &TargetValue ) -> UnorderedHashMap<TargetKey, TargetValue, BH>
where BH: Clone,

Aggregates values of the map using the given functions. mapping_function maps each key to a new key, possibly mapping multiple original keys to the same target key. reduce_function dictates how to aggregate any two values of the same target key. default_value is the initial value for each target key. Note! as the map is unordered, reduce_function should be commutative. Otherwise, the result is undefined (nondeterministic).

source

pub fn iter_sorted(&self) -> impl Iterator<Item = (&Key, &Value)>
where Key: Ord,

Iterates the map in an ascending order applied by the Ord implementation of Key. NOTE! To guarantee a deterministic output, the Ord implementation must apply a strict ordering. That is, a <= b and b <= a, then a == b. If Ord is derived (in all hierarchy levels), this is probably the case. If the ordering is not strict, the order of the output OrderedHashMap is undefined (nondeterministic). This can be used to convert an unordered map to an ordered map (mostly when the unordered map was used for intermediate processing).

source

pub fn into_iter_sorted(self) -> impl Iterator<Item = (Key, Value)>
where Key: Ord + Clone,

A consuming version of iter_sorted.

source

pub fn iter_sorted_by_key<TargetKey, F>( &self, f: F ) -> impl Iterator<Item = (&Key, &Value)>
where Key: Ord, TargetKey: Ord, F: FnMut(&(&Key, &Value)) -> TargetKey,

Iterates the map in an ascending order of the keys produced by the given function f. NOTE! To guarantee a deterministic output, f’s implementation must apply a strict ordering of the (Key, Value) pairs. That is, for any given pair of entries a=(k_a, v_a) and b=(k_b, v_b), if a <= b and b <= a, then a == b. If the ordering is not strict, the order of the output OrderedHashMap is undefined (nondeterministic). This can be used to convert an unordered map to an ordered map (mostly when the unordered map was used for intermediate processing).

source

pub fn into_iter_sorted_by_key<TargetKey, F>( self, f: F ) -> impl Iterator<Item = (Key, Value)>
where TargetKey: Ord, F: FnMut(&(Key, Value)) -> TargetKey,

A consuming version of iter_sorted_by_key.

source

pub fn filter<P>(self, p: P) -> Self
where BH: Default, P: FnMut(&Key, &Value) -> bool,

Creates a new map with only the elements from the original map for which the given predicate returns true.

Trait Implementations§

source§

impl<Key: Clone, Value: Clone, BH: Clone> Clone for UnorderedHashMap<Key, Value, BH>

source§

fn clone(&self) -> UnorderedHashMap<Key, Value, BH>

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<Key: Debug, Value: Debug, BH: Debug> Debug for UnorderedHashMap<Key, Value, BH>

source§

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

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

impl<Key, Value, BH: Default> Default for UnorderedHashMap<Key, Value, BH>

source§

fn default() -> Self

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

impl<Key: Hash + Eq, Value, const N: usize, BH: BuildHasher + Default> From<[(Key, Value); N]> for UnorderedHashMap<Key, Value, BH>

source§

fn from(items: [(Key, Value); N]) -> Self

Converts to this type from the input type.
source§

impl<Key: Hash + Eq, Value, BH: BuildHasher + Default> FromIterator<(Key, Value)> for UnorderedHashMap<Key, Value, BH>

source§

fn from_iter<T: IntoIterator<Item = (Key, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<Key, Q, Value, BH: BuildHasher> Index<&Q> for UnorderedHashMap<Key, Value, BH>
where Key: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized,

§

type Output = Value

The returned type after indexing.
source§

fn index(&self, key: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<Key, Value, BH> PartialEq for UnorderedHashMap<Key, Value, BH>
where Key: Eq + Hash, Value: PartialEq, BH: BuildHasher,

source§

fn eq(&self, other: &Self) -> 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<Key, Value, BH> Eq for UnorderedHashMap<Key, Value, BH>
where Key: Eq + Hash, Value: Eq, BH: BuildHasher,

Auto Trait Implementations§

§

impl<Key, Value, BH> RefUnwindSafe for UnorderedHashMap<Key, Value, BH>
where BH: RefUnwindSafe, Key: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Key, Value, BH> Send for UnorderedHashMap<Key, Value, BH>
where BH: Send, Key: Send, Value: Send,

§

impl<Key, Value, BH> Sync for UnorderedHashMap<Key, Value, BH>
where BH: Sync, Key: Sync, Value: Sync,

§

impl<Key, Value, BH> Unpin for UnorderedHashMap<Key, Value, BH>
where BH: Unpin, Key: Unpin, Value: Unpin,

§

impl<Key, Value, BH> UnwindSafe for UnorderedHashMap<Key, Value, BH>
where BH: UnwindSafe, Key: UnwindSafe, Value: 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
§

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

§

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.
source§

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

source§

fn upcast(&self) -> &T

source§

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

source§

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