#[repr(C)]
pub struct SmallMap<K, V> { /* private fields */ }
Expand description

An memory-efficient key-value map with deterministic order.

Provides the standard container operations, modelled most closely on indexmap::IndexMap, plus:

  • Variants which take an already hashed value, e.g. get_hashed.

  • Functions which work with the position, e.g. get_index_of.

Implementations§

source§

impl<K, V> SmallMap<K, V>

source

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

Empty map.

source

pub fn with_capacity(n: usize) -> SmallMap<K, V>

Create an empty map with specified capacity.

source

pub fn maybe_drop_index(&mut self)

Drop the index if the map is too small, and the index is not really needed.

We don’t allocate index prematurely when we add entries the map, but we keep it allocated when we remove entries from the map.

This function allows to reclaim memory after some entries are removed.

source

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

Key references iterator.

source

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

Value references iterator.

source

pub fn into_keys(self) -> IntoKeys<K, V>

Key owned iterator.

source

pub fn into_values(self) -> IntoValues<K, V>

Value owned iterator.

source

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

Mutable value references iterator.

source

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

Entry references iterator.

source

pub fn iter_hashed(&self) -> IterHashed<'_, K, V>

Entry references with hashes iterator.

source

pub fn into_iter_hashed(self) -> IntoIterHashed<K, V>

Entries with hashes iterator.

source

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

Mutable entry references iterator.

source

pub fn iter_mut_unchecked(&mut self) -> IterMutUnchecked<'_, K, V>

Mutable entry references iterator, with mutable key references.

This operation is memory safe, but otherwise no guarantees if keys are mutated inconsistently (hash or equality changes).

source

pub fn get_hashed<Q>(&self, key: Hashed<&Q>) -> Option<&V>
where Q: Equivalent<K> + ?Sized,

Query the map by a prehashed key.

source

pub fn get_hashed_by_value<Q>(&self, key: Hashed<Q>) -> Option<&V>
where Q: Equivalent<K>,

Same as get_hashed, byt takes key by value instead of by reference. Sometimes it generates slightly better code for small values.

source

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

Query the map by a given key.

source

pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
where Q: Hash + Equivalent<K> + ?Sized,

Query the map by a given key, return an index of the entry along with the entry key and value.

source

pub fn get_full_hashed<Q>(&self, key: Hashed<&Q>) -> Option<(usize, &K, &V)>
where Q: Equivalent<K> + ?Sized,

Query the map by a given key, return an index of the entry along with the entry key and value.

source

pub fn get_index_of_hashed<Q>(&self, key: Hashed<&Q>) -> Option<usize>
where Q: Equivalent<K> + ?Sized,

Find the index of the given hashed key.

source

pub fn get_index_of_hashed_by_value<Q>(&self, key: Hashed<Q>) -> Option<usize>
where Q: Equivalent<K>,

Get the index of the entry given a hashed key.

source

pub fn get_index(&self, index: usize) -> Option<(&K, &V)>

Find an entry by an index.

source

pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
where Q: Hash + Equivalent<K> + ?Sized,

The an entry index by a given key.

source

pub fn get_mut_hashed<Q>(&mut self, key: Hashed<&Q>) -> Option<&mut V>
where Q: Equivalent<K> + ?Sized,

Find a mutable value by a hashed key.

source

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

Find the entry by a given key.

source

pub fn contains_key_hashed<Q>(&self, key: Hashed<&Q>) -> bool
where Q: Equivalent<K> + ?Sized,

Find if an entry by a given prehashed key exists.

source

pub fn contains_key_hashed_by_value<Q>(&self, key: Hashed<Q>) -> bool
where Q: Equivalent<K>,

Find if an entry by a given hashed key exists.

source

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

Find if an entry by a given key exists.

source

pub fn reserve(&mut self, additional: usize)
where K: Eq,

Reserve capacity for at least additional more elements to be inserted.

source

pub fn capacity(&self) -> usize

Current map capacity.

source

pub fn first(&self) -> Option<(&K, &V)>

Returns a reference to the first key-value pair.

source

pub fn last(&self) -> Option<(&K, &V)>

Returns a reference to the last key-value pair.

source

pub fn insert_hashed_unique_unchecked( &mut self, key: Hashed<K>, val: V ) -> (&K, &mut V)

Insert an entry into the map without checking for a duplicate key.

source

pub fn insert_hashed(&mut self, key: Hashed<K>, val: V) -> Option<V>
where K: Eq,

Insert a key-value pair into the map.

source

pub fn insert(&mut self, key: K, val: V) -> Option<V>
where K: Hash + Eq,

Insert a key-value pair into the map.

source

pub fn insert_unique_unchecked(&mut self, key: K, val: V) -> (&K, &mut V)
where K: Hash,

Insert a key-value pair into the map without checking for a duplicate key.

source

pub fn remove_hashed<Q>(&mut self, key: Hashed<&Q>) -> Option<V>
where Q: Equivalent<K> + ?Sized,

Remove the entry for the key.

Time complexity of this operation is O(N) where N is the number of entries in the map.

source

pub fn remove_hashed_entry<Q>(&mut self, key: Hashed<&Q>) -> Option<(K, V)>
where Q: Equivalent<K> + ?Sized,

Remove the entry for the key.

Time complexity of this operation is O(N) where N is the number of entries in the map.

source

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

Remove the entry for the key.

Time complexity of this operation is O(N) where N is the number of entries in the map.

source

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

Remove the entry for the key.

Time complexity of this operation is O(N) where N is the number of entries in the map.

source

pub fn entry_hashed(&mut self, key: Hashed<K>) -> Entry<'_, K, V>
where K: Eq,

Get the entry (occupied or not) for the key.

source

pub fn pop(&mut self) -> Option<(K, V)>

Remove the last element.

source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
where K: Eq + Hash,

Get the entry (occupied or not) for the key.

source

pub fn is_empty(&self) -> bool

Is the map empty?

source

pub fn len(&self) -> usize

Get the number of elements in the map.

source

pub fn clear(&mut self)

Remove all elements from the map.

Retain the capacity.

source

pub fn sort_keys(&mut self)
where K: Ord,

Sort entries by key.

source

pub fn eq_ordered(&self, other: &SmallMap<K, V>) -> bool
where K: PartialEq, V: PartialEq,

Equal if the keys and values are equal in the iteration order.

source

pub fn hash_ordered<H>(&self, state: &mut H)
where H: Hasher, K: Hash, V: Hash,

Hash entries in the iteration order.

Note, keys are not hashed, but previously computed hashes are hashed instead.

source

pub fn reverse(&mut self)

Reverse the iteration order of the map.

Trait Implementations§

source§

impl<'a, K: 'a + StarlarkTypeRepr, V: 'a + StarlarkTypeRepr> AllocFrozenValue for &'a SmallMap<K, V>

source§

fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue

Allocate a value in the frozen heap and return a reference to the allocated value.
source§

impl<K: AllocFrozenValue, V: AllocFrozenValue> AllocFrozenValue for SmallMap<K, V>

source§

fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue

Allocate a value in the frozen heap and return a reference to the allocated value.
source§

impl<'a, 'v, K: 'a + StarlarkTypeRepr, V: 'a + StarlarkTypeRepr> AllocValue<'v> for &'a SmallMap<K, V>
where &'a K: AllocValue<'v>, &'a V: AllocValue<'v>,

source§

fn alloc_value(self, heap: &'v Heap) -> Value<'v>

Allocate the value on a heap and return a reference to the allocated value. Read more
source§

impl<'v, K: AllocValue<'v>, V: AllocValue<'v>> AllocValue<'v> for SmallMap<K, V>

source§

fn alloc_value(self, heap: &'v Heap) -> Value<'v>

Allocate the value on a heap and return a reference to the allocated value. Read more
source§

impl<K, V> Allocative for SmallMap<K, V>
where K: Allocative, V: Allocative,

source§

fn visit<'allocative_a, 'allocative_b>( &self, visitor: &'allocative_a mut Visitor<'allocative_b> )
where 'allocative_b: 'allocative_a,

source§

impl<K, V> Clone for SmallMap<K, V>
where K: Clone, V: Clone,

source§

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

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<K, V> Debug for SmallMap<K, V>
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> Default for SmallMap<K, V>

source§

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

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

impl<'de, K, V> Deserialize<'de> for SmallMap<K, V>
where K: Deserialize<'de> + Hash + Eq, V: Deserialize<'de>,

source§

fn deserialize<D>( deserializer: D ) -> Result<SmallMap<K, V>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

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

source§

fn extend<T>(&mut self, iter: T)
where T: 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<K, V> Freeze for SmallMap<K, V>
where K: Freeze, V: Freeze,

§

type Frozen = SmallMap<<K as Freeze>::Frozen, <V as Freeze>::Frozen>

When type is frozen, it is frozen into this type.
source§

fn freeze(self, freezer: &Freezer) -> Result<SmallMap<K::Frozen, V::Frozen>>

Freeze a value. The frozen value must be equal to the original, and produce the same hash. Read more
source§

impl<K, V> FromIterator<(Hashed<K>, V)> for SmallMap<K, V>
where K: Eq,

source§

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

Creates a value from an iterator. Read more
source§

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

source§

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

Creates a value from an iterator. Read more
source§

impl<'a, K, V> IntoIterator for &'a SmallMap<K, V>

§

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

The type of the elements being iterated over.
§

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

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

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

Creates an iterator from a value. Read more
source§

impl<'a, K, V> IntoIterator for &'a mut SmallMap<K, V>

§

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

The type of the elements being iterated over.
§

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

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

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

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for SmallMap<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

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

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

Creates an iterator from a value. Read more
source§

impl<K, V> PartialEq for SmallMap<K, V>
where K: Eq, V: PartialEq,

source§

fn eq(&self, other: &SmallMap<K, V>) -> 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<K, V> Serialize for SmallMap<K, V>
where K: Serialize, V: Serialize,

source§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'a, K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for &'a SmallMap<K, V>

source§

fn starlark_type_repr() -> Ty

The representation of a type that a user would use verbatim in starlark type annotations
source§

impl<K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for SmallMap<K, V>

source§

fn starlark_type_repr() -> Ty

The representation of a type that a user would use verbatim in starlark type annotations
source§

impl<'v, K: Trace<'v>, V: Trace<'v>> Trace<'v> for SmallMap<K, V>

source§

fn trace(&mut self, tracer: &Tracer<'v>)

Recursively “trace” the value. Read more
source§

impl<'v, K: UnpackValue<'v> + Hash + Eq, V: UnpackValue<'v>> UnpackValue<'v> for SmallMap<K, V>

source§

fn expected() -> String

Description of values acceptable by unpack_value, e. g. list or str.
source§

fn unpack_value(value: Value<'v>) -> Option<Self>

Given a Value, try and unpack it into the given type, which may involve some element of conversion.
source§

fn unpack_value_err(value: Value<'v>) -> Result<Self>

Unpack a value, but return error instead of None if unpacking fails.
source§

fn unpack_param(value: Value<'v>) -> Result<Self>

Unpack value, but instead of None return error about incorrect argument type.
source§

fn unpack_named_param(value: Value<'v>, param_name: &str) -> Result<Self>

Unpack value, but instead of None return error about incorrect named argument type.
source§

impl<FromK, FromV, ToK, ToV> Coerce<SmallMap<ToK, ToV>> for SmallMap<FromK, FromV>
where FromK: CoerceKey<ToK>, FromV: Coerce<ToV>,

source§

impl<K, V> Eq for SmallMap<K, V>
where K: Eq, V: Eq,

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for SmallMap<K, V>

§

impl<K, V> Send for SmallMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for SmallMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for SmallMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for SmallMap<K, V>
where K: 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<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> Serialize for T
where T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,