Struct starlark_map::small_map::SmallMap
source · #[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>
impl<K, V> SmallMap<K, V>
sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create an empty map with specified capacity.
sourcepub fn maybe_drop_index(&mut self)
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.
sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
Value owned iterator.
sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Mutable value references iterator.
sourcepub fn iter_hashed(&self) -> IterHashed<'_, K, V> ⓘ
pub fn iter_hashed(&self) -> IterHashed<'_, K, V> ⓘ
Entry references with hashes iterator.
sourcepub fn into_iter_hashed(self) -> IntoIterHashed<K, V> ⓘ
pub fn into_iter_hashed(self) -> IntoIterHashed<K, V> ⓘ
Entries with hashes iterator.
sourcepub fn iter_mut_unchecked(&mut self) -> IterMutUnchecked<'_, K, V> ⓘ
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).
sourcepub fn get_hashed<Q>(&self, key: Hashed<&Q>) -> Option<&V>where
Q: Equivalent<K> + ?Sized,
pub fn get_hashed<Q>(&self, key: Hashed<&Q>) -> Option<&V>where
Q: Equivalent<K> + ?Sized,
Query the map by a prehashed key.
sourcepub fn get_hashed_by_value<Q>(&self, key: Hashed<Q>) -> Option<&V>where
Q: Equivalent<K>,
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.
sourcepub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
Query the map by a given key, return an index of the entry along with the entry key and value.
sourcepub fn get_full_hashed<Q>(&self, key: Hashed<&Q>) -> Option<(usize, &K, &V)>where
Q: Equivalent<K> + ?Sized,
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.
sourcepub fn get_index_of_hashed<Q>(&self, key: Hashed<&Q>) -> Option<usize>where
Q: Equivalent<K> + ?Sized,
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.
sourcepub fn get_index_of_hashed_by_value<Q>(&self, key: Hashed<Q>) -> Option<usize>where
Q: Equivalent<K>,
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.
sourcepub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
The an entry index by a given key.
sourcepub fn get_mut_hashed<Q>(&mut self, key: Hashed<&Q>) -> Option<&mut V>where
Q: Equivalent<K> + ?Sized,
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.
sourcepub fn contains_key_hashed<Q>(&self, key: Hashed<&Q>) -> boolwhere
Q: Equivalent<K> + ?Sized,
pub fn contains_key_hashed<Q>(&self, key: Hashed<&Q>) -> boolwhere
Q: Equivalent<K> + ?Sized,
Find if an entry by a given prehashed key exists.
sourcepub fn contains_key_hashed_by_value<Q>(&self, key: Hashed<Q>) -> boolwhere
Q: Equivalent<K>,
pub fn contains_key_hashed_by_value<Q>(&self, key: Hashed<Q>) -> boolwhere
Q: Equivalent<K>,
Find if an entry by a given hashed key exists.
sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Find if an entry by a given key exists.
sourcepub fn reserve(&mut self, additional: usize)where
K: Eq,
pub fn reserve(&mut self, additional: usize)where
K: Eq,
Reserve capacity for at least additional
more elements to be inserted.
sourcepub fn insert_hashed_unique_unchecked(
&mut self,
key: Hashed<K>,
val: V
) -> (&K, &mut V)
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.
sourcepub fn insert_hashed(&mut self, key: Hashed<K>, val: V) -> Option<V>where
K: Eq,
pub fn insert_hashed(&mut self, key: Hashed<K>, val: V) -> Option<V>where
K: Eq,
Insert a key-value pair into the map.
sourcepub fn insert_unique_unchecked(&mut self, key: K, val: V) -> (&K, &mut V)where
K: Hash,
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.
sourcepub fn remove_hashed<Q>(&mut self, key: Hashed<&Q>) -> Option<V>where
Q: ?Sized + Equivalent<K>,
pub fn remove_hashed<Q>(&mut self, key: Hashed<&Q>) -> Option<V>where
Q: ?Sized + Equivalent<K>,
Remove the entry for the key.
Time complexity of this operation is O(N) where N is the number of entries in the map.
sourcepub fn remove_hashed_entry<Q>(&mut self, key: Hashed<&Q>) -> Option<(K, V)>where
Q: ?Sized + Equivalent<K>,
pub fn remove_hashed_entry<Q>(&mut self, key: Hashed<&Q>) -> Option<(K, V)>where
Q: ?Sized + Equivalent<K>,
Remove the entry for the key.
Time complexity of this operation is O(N) where N is the number of entries in the map.
sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Remove the entry for the key.
Time complexity of this operation is O(N) where N is the number of entries in the map.
sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Remove the entry for the key.
Time complexity of this operation is O(N) where N is the number of entries in the map.
sourcepub fn entry_hashed(&mut self, key: Hashed<K>) -> Entry<'_, K, V>where
K: Eq,
pub fn entry_hashed(&mut self, key: Hashed<K>) -> Entry<'_, K, V>where
K: Eq,
Get the entry (occupied or not) for the key.
sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Get the entry (occupied or not) for the key.
sourcepub fn eq_ordered(&self, other: &Self) -> bool
pub fn eq_ordered(&self, other: &Self) -> bool
Equal if the keys and values are equal in the iteration order.
sourcepub fn hash_ordered<H: Hasher>(&self, state: &mut H)
pub fn hash_ordered<H: Hasher>(&self, state: &mut H)
Hash entries in the iteration order.
Note, keys are not hashed, but previously computed hashes are hashed instead.
Trait Implementations§
source§impl<K: Allocative, V: Allocative> Allocative for SmallMap<K, V>
impl<K: Allocative, V: Allocative> Allocative for SmallMap<K, V>
source§impl<'de, K, V> Deserialize<'de> for SmallMap<K, V>
impl<'de, K, V> Deserialize<'de> for SmallMap<K, V>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<K, V> Extend<(K, V)> for SmallMap<K, V>
impl<K, V> Extend<(K, V)> for SmallMap<K, V>
source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
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<K, V> From<SmallMap<K, V>> for OrderedMap<K, V>
impl<K, V> From<SmallMap<K, V>> for OrderedMap<K, V>
source§fn from(map: SmallMap<K, V>) -> OrderedMap<K, V>
fn from(map: SmallMap<K, V>) -> OrderedMap<K, V>
source§impl<K, V> FromIterator<(K, V)> for SmallMap<K, V>
impl<K, V> FromIterator<(K, V)> for SmallMap<K, V>
source§impl<'a, K, V> IntoIterator for &'a SmallMap<K, V>
impl<'a, K, V> IntoIterator for &'a SmallMap<K, V>
source§impl<'a, K, V> IntoIterator for &'a mut SmallMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut SmallMap<K, V>
source§impl<K, V> IntoIterator for SmallMap<K, V>
impl<K, V> IntoIterator for SmallMap<K, V>
source§impl<K: Eq, V: PartialEq> PartialEq for SmallMap<K, V>
impl<K: Eq, V: PartialEq> PartialEq for SmallMap<K, V>
impl<K: Eq, V: Eq> Eq for SmallMap<K, V>
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for SmallMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SmallMap<K, V>
impl<K, V> Sync for SmallMap<K, V>
impl<K, V> Unpin for SmallMap<K, V>
impl<K, V> UnwindSafe for SmallMap<K, V>where
K: UnwindSafe,
V: 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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.