Struct tantivy_stacker::SharedArenaHashMap
source · pub struct SharedArenaHashMap { /* private fields */ }
Expand description
Customized HashMap
with &[u8]
keys
Its main particularity is that rather than storing its keys in the heap, keys are stored in a memory arena inline with the values.
The quirky API has the benefit of avoiding the computation of the hash of the key twice, or copying the key as long as there is no insert.
SharedArenaHashMap is like ArenaHashMap but gets the memory arena passed as an argument to the methods. So one MemoryArena can be shared with multiple SharedArenaHashMap.
Implementations§
pub fn with_capacity(table_size: usize) -> SharedArenaHashMap
pub fn mem_usage(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
pub fn iter<'a>(&'a self, memory_arena: &'a MemoryArena) -> Iter<'_>
sourcepub fn get<V>(&self, key: &[u8], memory_arena: &MemoryArena) -> Option<V>where
V: Copy + 'static,
pub fn get<V>(&self, key: &[u8], memory_arena: &MemoryArena) -> Option<V>where
V: Copy + 'static,
Get a value associated to a key.
sourcepub fn mutate_or_create<V>(
&mut self,
key: &[u8],
memory_arena: &mut MemoryArena,
updater: impl FnMut(Option<V>) -> V
) -> Vwhere
V: Copy + 'static,
pub fn mutate_or_create<V>(
&mut self,
key: &[u8],
memory_arena: &mut MemoryArena,
updater: impl FnMut(Option<V>) -> V
) -> Vwhere
V: Copy + 'static,
update
create a new entry for a given key if it does not exist
or updates the existing entry.
The actual logic for this update is define in the updater
argument.
If the key is not present, updater
will receive None
and
will be in charge of returning a default value.
If the key already as an associated value, then it will be passed
Some(previous_value)
.
The key will be truncated to u16::MAX bytes.