Skip to main content

SmallMap

Struct SmallMap 

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

Source

pub fn new() -> SmallMap<K, V, N>

Creates an empty SmallMap. Does not allocate until it grows past N entries.

Source

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.

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

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. A previously promoted map stays promoted; see the SmallMap documentation.

Source

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

Retains only the elements specified by the predicate.

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

Source

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

Returns an iterator over the map’s key-value pairs.

Source

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

Returns a mutable iterator over the map’s key-value pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Returns an iterator over the map’s keys.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Returns an iterator over the map’s values.

Source

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>
where K: Hash + Eq,

Source

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.

Source

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

Returns a reference to the value corresponding to the key.

Source

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

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

Source

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

Returns the key-value pair corresponding to the supplied key.

Source

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

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

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: 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.

Source

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

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

Trait Implementations§

Source§

impl<K, V, const N: usize> Clone for SmallMap<K, V, N>
where K: Clone, V: Clone,

Source§

fn clone(&self) -> SmallMap<K, V, N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K, V, const N: usize> Debug for SmallMap<K, V, N>
where K: Debug, V: Debug,

Source§

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

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

impl<K, V, const N: usize> Default for SmallMap<K, V, N>

Source§

fn default() -> SmallMap<K, V, N>

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

impl<K, V, const N: usize> Eq for SmallMap<K, V, N>
where K: Hash + Eq, V: Eq,

Source§

impl<K, V, const N: usize> Extend<(K, V)> for SmallMap<K, V, N>
where K: Hash + Eq,

Source§

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

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 From<SmallMap<Identifier, Box<dyn Attribute>, 1>> for AttributeDict

Source§

fn from(value: SmallMap<Identifier, Box<dyn Attribute>, 1>) -> AttributeDict

Converts to this type from the input type.
Source§

impl<K, V, const N: usize> FromIterator<(K, V)> for SmallMap<K, V, N>
where K: Hash + Eq,

Source§

fn from_iter<I>(iter: I) -> SmallMap<K, V, N>
where I: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
Source§

impl<K, V, const N: usize> IntoIterator for SmallMap<K, V, N>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = MapIntoIter<K, V, N>

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

fn into_iter(self) -> <SmallMap<K, V, N> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, const N: usize> IntoIterator for &'a SmallMap<K, V, N>

Source§

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

The type of the elements being iterated over.
Source§

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

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

fn into_iter(self) -> <&'a SmallMap<K, V, N> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, V, const N: usize> PartialEq for SmallMap<K, V, N>
where K: Hash + Eq, V: PartialEq,

Source§

fn eq(&self, other: &SmallMap<K, V, N>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

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.