pub enum SmallHashMap<K: Eq + Hash, V, const N: usize, const M: usize> {
Small(SmallVec<[(K, V); N]>),
Large(HashMap<K, V>),
}Expand description
A hash map optimized for small sizes,
with a small size optimization for up to N entries
and then a vector for up to M
and then finally falling back to a real hash map after M.
The inline and heap based vectors use linear scans, which is faster than hashing as long as the map is small.
Variants§
Implementations§
Source§impl<K: Eq + Hash, V, const N: usize, const M: usize> SmallHashMap<K, V, N, M>
impl<K: Eq + Hash, V, const N: usize, const M: usize> SmallHashMap<K, V, N, M>
pub fn new() -> Self
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts the association key -> value into the map,
returning the previous value for key, if any.
Sourcepub fn get_or_insert(&mut self, key: K, or_insert: impl FnOnce() -> V) -> &mut V
pub fn get_or_insert(&mut self, key: K, or_insert: impl FnOnce() -> V) -> &mut V
Returns either the existing value for key
or inserts into key using or_insert.
pub fn remove(&mut self, key: &K) -> Option<V>
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (&K, &V)>
pub fn iter(&self) -> impl ExactSizeIterator<Item = (&K, &V)>
Returns an iterator over all the key-value pairs in the map.
Sourcepub fn keys(&self) -> impl ExactSizeIterator<Item = &K>
pub fn keys(&self) -> impl ExactSizeIterator<Item = &K>
Returns an iterator over all the keys in the map.
Sourcepub fn values(&self) -> impl ExactSizeIterator<Item = &V>
pub fn values(&self) -> impl ExactSizeIterator<Item = &V>
Returns an iterator over all the values in the map.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns whether key is in the map.
Trait Implementations§
Source§impl<K: Clone + Eq + Hash, V: Clone, const N: usize, const M: usize> Clone for SmallHashMap<K, V, N, M>
impl<K: Clone + Eq + Hash, V: Clone, const N: usize, const M: usize> Clone for SmallHashMap<K, V, N, M>
Source§fn clone(&self) -> SmallHashMap<K, V, N, M>
fn clone(&self) -> SmallHashMap<K, V, N, M>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K: Debug + Eq + Hash, V: Debug, const N: usize, const M: usize> Debug for SmallHashMap<K, V, N, M>
impl<K: Debug + Eq + Hash, V: Debug, const N: usize, const M: usize> Debug for SmallHashMap<K, V, N, M>
Source§impl<K: Eq + Hash, V, const N: usize, const M: usize> Extend<(K, V)> for SmallHashMap<K, V, N, M>
impl<K: Eq + Hash, V, const N: usize, const M: usize> Extend<(K, V)> for SmallHashMap<K, V, N, M>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
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)
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)
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: PartialEq + Eq + Hash, V: PartialEq, const N: usize, const M: usize> PartialEq for SmallHashMap<K, V, N, M>
impl<K: PartialEq + Eq + Hash, V: PartialEq, const N: usize, const M: usize> PartialEq for SmallHashMap<K, V, N, M>
impl<K: Eq + Eq + Hash, V: Eq, const N: usize, const M: usize> Eq for SmallHashMap<K, V, N, M>
impl<K: Eq + Hash, V, const N: usize, const M: usize> StructuralPartialEq for SmallHashMap<K, V, N, M>
Auto Trait Implementations§
impl<K, V, const N: usize, const M: usize> Freeze for SmallHashMap<K, V, N, M>
impl<K, V, const N: usize, const M: usize> RefUnwindSafe for SmallHashMap<K, V, N, M>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, const N: usize, const M: usize> Send for SmallHashMap<K, V, N, M>
impl<K, V, const N: usize, const M: usize> Sync for SmallHashMap<K, V, N, M>
impl<K, V, const N: usize, const M: usize> Unpin for SmallHashMap<K, V, N, M>
impl<K, V, const N: usize, const M: usize> UnsafeUnpin for SmallHashMap<K, V, N, M>where
K: UnsafeUnpin,
V: UnsafeUnpin,
impl<K, V, const N: usize, const M: usize> UnwindSafe for SmallHashMap<K, V, N, M>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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>
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 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>
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