ArenaHashMap

Struct ArenaHashMap 

Source
pub struct ArenaHashMap { /* 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.

Implementations§

Source§

impl ArenaHashMap

Source

pub fn new(table_size: usize) -> ArenaHashMap

Source

pub fn read<Item: Copy + 'static>(&self, addr: Addr) -> Item

Source

pub fn mem_usage(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn iter(&self) -> Iter<'_>

Source

pub fn mutate_or_create<V, TMutator>( &mut self, key: &[u8], updater: TMutator, ) -> UnorderedId
where V: Copy + 'static, TMutator: FnMut(Option<V>) -> V,

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

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.