pub struct InlineHashMap<K, V, const N: usize>(/* private fields */);Expand description
Similar to InlineVec, this structure will use an array if it is small enough to live on the stack, otherwise it allocates a HashMap on the heap
Hashing can be slower than just iterating through an array if the array is small, which is where it makes most sense
Implementations§
Source§impl<K, V, const N: usize> InlineHashMap<K, V, N>
impl<K, V, const N: usize> InlineHashMap<K, V, N>
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Returns an iterator over the elements of this map
This can iterate over either stack-backed entries or, in std builds,
heap-backed entries.
Sourcepub unsafe fn inline_parts_mut(
&mut self,
) -> Option<(&mut [MaybeUninit<(K, V)>; N], usize)>
pub unsafe fn inline_parts_mut( &mut self, ) -> Option<(&mut [MaybeUninit<(K, V)>; N], usize)>
If self is inlined, this returns the underlying raw parts that make up this InlineHashMap.
Only the first .1 elements are initialized.
fn mutate<K: core::hash::Hash + Eq, V, const N: usize>(values: &mut tl::inline::hashmap::InlineHashMap<K, V, N>) {
let _ = values.inline_parts_mut(); // an unsafe call is required
}§Safety
Before the borrow ends, the initialized prefix must contain valid, uniquely
owned values of the element type. Replacing a slot with uninitialized data,
duplicating an owner or dropping it without replacing it violates this contract.
Prefer get_mut or typed mutable access instead.
Sourcepub fn is_heap_allocated(&self) -> bool
pub fn is_heap_allocated(&self) -> bool
Checks whether this vector is allocated on the heap
Sourcepub fn insert(&mut self, key: K, value: V) -> Result<(), ParseError>
pub fn insert(&mut self, key: K, value: V) -> Result<(), ParseError>
Inserts a new element into the map
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Removes an element from the map, and returns ownership over the value
Sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key.
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Checks whether the map contains a value for the specified key.