Skip to main content

OwnedMap

Struct OwnedMap 

Source
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>

Source

pub fn memory(&self) -> &Memory

The shared account retained until the table is deallocated.

Source

pub fn len(&self) -> usize

Number of initialized entries.

Source

pub fn is_empty(&self) -> bool

Whether there are no entries.

Source

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)));
Source

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);
Source

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));
Source

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.

Source

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);

Trait Implementations§

Source§

impl<K: HashWork + Debug, V: Debug, W: Work> Debug for OwnedMap<K, V, W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, W = Memory> !Freeze for OwnedMap<K, V, W>

§

impl<K, V, W> RefUnwindSafe for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: RefUnwindSafe, W: RefUnwindSafe,

§

impl<K, V, W> Send for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: Send, W: Send,

§

impl<K, V, W> Sync for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: Sync, W: Sync,

§

impl<K, V, W> Unpin for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: Unpin, W: Unpin,

§

impl<K, V, W> UnsafeUnpin for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: UnsafeUnpin, W: UnsafeUnpin,

§

impl<K, V, W> UnwindSafe for OwnedMap<K, V, W>
where HashMap<K, V, DefaultHashBuilder, AccountAllocator<W>>: UnwindSafe, W: 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.