pub struct OwnedMap<K: HashWork, V, W: Work = Memory> { /* private fields */ }Expand description
A hash map whose backing allocation and operations share one resource domain.
Hashbrown supplies bucket/probing/SIMD machinery. Reservations include its control bytes and alignment, not merely the initialized entries. Hashing and actual collision comparisons are admitted before examining candidate keys.
Implementations§
Source§impl<K: HashWork, V, W: Work> OwnedMap<K, V, W>
impl<K: HashWork, V, W: Work> OwnedMap<K, V, W>
Sourcepub fn try_iter<'a, E: Work>(
&'a self,
execution: &E,
) -> Result<impl Iterator<Item = (&'a K, &'a V)> + 'a + use<'a, K, V, W, E>, MemoryError>
pub fn try_iter<'a, E: Work>( &'a self, execution: &E, ) -> Result<impl Iterator<Item = (&'a K, &'a V)> + 'a + use<'a, K, V, W, E>, MemoryError>
Borrowed entries after admitting a full control-bucket traversal in the current execution domain, independently of retained storage. Sparse holes count too. Partial consumption retains the conservative prepayment; the opaque iterator exposes no cloning/restart operation.
§Examples
let mut map = memory.map();
map.try_insert(1usize, 42)?;
let mut entries = map.try_iter(&memory)?;
assert_eq!(entries.next(), Some((&1, &42)));Sourcepub fn get(
&self,
key: &K,
execution: &impl Work,
) -> Result<Option<&V>, MemoryError>
pub fn get( &self, key: &K, execution: &impl Work, ) -> Result<Option<&V>, MemoryError>
Looks up a key after admitting its complete possible probe work. The current execution domain pays independently of stored capacity.
§Examples
assert_eq!(map.get(&1, &memory)?, Some(&42));
assert_eq!(map.get(&2, &memory)?, None);Sourcepub fn get_mut(
&mut self,
key: &K,
execution: &impl Work,
) -> Result<Option<&mut V>, MemoryError>
pub fn get_mut( &mut self, key: &K, execution: &impl Work, ) -> Result<Option<&mut V>, MemoryError>
Looks up an entry for mutation without exposing table growth. Hashing, probing and equality use the supplied execution domain.
§Examples
if let Some(value) = map.get_mut(&1, &memory)? { *value = 7; }
assert_eq!(map.get(&1, &memory)?, Some(&7));Sourcepub fn try_insert(&mut self, key: K, value: V) -> Result<Option<V>, MemoryError>
pub fn try_insert(&mut self, key: K, value: V) -> Result<Option<V>, MemoryError>
Inserts a value fallibly, or replaces the value for an existing key. This storage mutation runs in the collection’s original resource domain, including hashing, rehashing, allocation and copying work. To mutate under a different domain, build a new collection there from explicitly admitted borrowed entries; retained capacity is not rebound.
Sourcepub fn remove(
&mut self,
key: &K,
execution: &impl Work,
) -> Result<Option<V>, MemoryError>
pub fn remove( &mut self, key: &K, execution: &impl Work, ) -> Result<Option<V>, MemoryError>
Removes an entry, retaining table capacity and its storage charge. The supplied execution domain pays for lookup and removal before mutation.
§Examples
let capacity_charge = memory.used();
assert_eq!(map.remove(&1, &memory)?, Some(42));
assert_eq!(memory.used(), capacity_charge);