pub struct SmallMap<K, V, const N: usize>(/* private fields */);Expand description
A hash map, with a fast non-cryptographic hasher and deterministic iteration order, optimized for the common case of very few entries.
Up to N entries are stored inline, in a flat, linearly-scanned
array, with no heap allocation and no hashing. Once an insert
grows the map past N entries, it transparently and permanently
promotes itself to an IMap
Implementations§
Source§impl<K, V, const N: usize> SmallMap<K, V, N>
impl<K, V, const N: usize> SmallMap<K, V, N>
Sourcepub fn new() -> SmallMap<K, V, N>
pub fn new() -> SmallMap<K, V, N>
Creates an empty SmallMap. Does not allocate until it grows
past N entries.
Sourcepub fn is_inline(&self) -> bool
pub fn is_inline(&self) -> bool
Returns true if this map has not (yet) grown past N
entries, i.e., is still using inline, non-heap-allocated
storage.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. A previously promoted map stays promoted; see the SmallMap documentation.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v) such that f(&k, &mut v) returns false.
Sourcepub fn iter_mut(&mut self) -> MapIterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> MapIterMut<'_, K, V> ⓘ
Returns a mutable iterator over the map’s key-value pairs.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut V>
Returns a mutable iterator over the map’s values.
Source§impl<K, V, const N: usize> SmallMap<K, V, N>
impl<K, V, const N: usize> SmallMap<K, V, N>
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
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.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for the specified
key.
Trait Implementations§
impl<K, V, const N: usize> Eq for SmallMap<K, V, N>
Source§impl<K, V, const N: usize> Extend<(K, V)> for SmallMap<K, V, N>
impl<K, V, const N: usize> Extend<(K, V)> for SmallMap<K, V, N>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<SmallMap<Identifier, Box<dyn Attribute>, 1>> for AttributeDict
impl From<SmallMap<Identifier, Box<dyn Attribute>, 1>> for AttributeDict
Source§fn from(value: SmallMap<Identifier, Box<dyn Attribute>, 1>) -> AttributeDict
fn from(value: SmallMap<Identifier, Box<dyn Attribute>, 1>) -> AttributeDict
Source§impl<K, V, const N: usize> IntoIterator for SmallMap<K, V, N>
impl<K, V, const N: usize> IntoIterator for SmallMap<K, V, N>
Source§impl<'a, K, V, const N: usize> IntoIterator for &'a SmallMap<K, V, N>
impl<'a, K, V, const N: usize> IntoIterator for &'a SmallMap<K, V, N>
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for SmallMap<K, V, N>where
MapRepr<K, V, N>: Freeze,
impl<K, V, const N: usize> RefUnwindSafe for SmallMap<K, V, N>where
MapRepr<K, V, N>: RefUnwindSafe,
impl<K, V, const N: usize> Send for SmallMap<K, V, N>where
MapRepr<K, V, N>: Send,
impl<K, V, const N: usize> Sync for SmallMap<K, V, N>where
MapRepr<K, V, N>: Sync,
impl<K, V, const N: usize> Unpin for SmallMap<K, V, N>where
MapRepr<K, V, N>: Unpin,
impl<K, V, const N: usize> UnsafeUnpin for SmallMap<K, V, N>where
MapRepr<K, V, N>: UnsafeUnpin,
impl<K, V, const N: usize> UnwindSafe for SmallMap<K, V, N>where
MapRepr<K, V, N>: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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
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> ⓘ
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> ⓘ
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