Skip to main content

FixedMap

Struct FixedMap 

Source
pub struct FixedMap<'a, const N: usize, const K: usize, const V: usize, H = FastHasher> { /* private fields */ }
Expand description

A fixed-capacity hashmap over caller-provided storage.

N is the maximum number of entries, and K and V are the fixed key and value sizes. The map uses 2 * N caller-provided slots, keeping occupancy at or below 50%. The map itself does not allocate. Deletion is not supported.

Implementations§

Source§

impl<'a, const N: usize, const K: usize, const V: usize, H: KeyHasher<K>> FixedMap<'a, N, K, V, H>

Source

pub fn with_hasher( entries: &'a mut [EntryStorage<K, V>], tags: &'a mut [u8], hasher: H, ) -> Result<Self, StorageError>

Creates an empty map with a custom key hasher and supplied storage.

entries and tags must each contain at least 2 * N elements. The required tags are cleared.

Source

pub const fn capacity(&self) -> usize

Returns the map’s fixed capacity.

Source

pub const fn len(&self) -> usize

Returns the number of entries currently stored.

Source

pub const fn is_empty(&self) -> bool

Returns whether the map contains no entries.

Source

pub const fn is_full(&self) -> bool

Returns whether the map has reached its capacity.

Source

pub fn get(&self, key: &[u8; K]) -> Option<&[u8; V]>

Gets a reference to the value for key, if present.

Source

pub fn get_mut(&mut self, key: &[u8; K]) -> Option<&mut [u8; V]>

Gets a mutable reference to the value for key, if present.

Source

pub fn insert( &mut self, key: [u8; K], value: [u8; V], ) -> Result<Option<[u8; V]>, InsertError<K, V>>

Inserts a key-value pair.

If the key already exists, its value is replaced and the old value is returned. If the map is full, the key and value are returned unchanged.

Source§

impl<'a, const N: usize, const K: usize, const V: usize> FixedMap<'a, N, K, V, FastHasher>

Source

pub fn new( entries: &'a mut [EntryStorage<K, V>], tags: &'a mut [u8], ) -> Result<Self, StorageError>

Creates an empty map using the default fast, non-cryptographic hasher.

Auto Trait Implementations§

§

impl<'a, const N: usize, const K: usize, const V: usize, H = FastHasher> !UnwindSafe for FixedMap<'a, N, K, V, H>

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Forget for FixedMap<'a, N, K, V, H>

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Freeze for FixedMap<'a, N, K, V, H>
where &'a mut [MaybeUninit<([u8; K], [u8; V])>]: Freeze, &'a mut [u8]: Freeze, H: Freeze,

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Move for FixedMap<'a, N, K, V, H>

§

impl<'a, const N: usize, const K: usize, const V: usize, H> RefUnwindSafe for FixedMap<'a, N, K, V, H>
where H: RefUnwindSafe,

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Send for FixedMap<'a, N, K, V, H>
where H: Send,

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Sync for FixedMap<'a, N, K, V, H>
where H: Sync,

§

impl<'a, const N: usize, const K: usize, const V: usize, H> Unpin for FixedMap<'a, N, K, V, H>
where H: Unpin, &'a mut [MaybeUninit<([u8; K], [u8; V])>]: Unpin, &'a mut [u8]: Unpin,

§

impl<'a, const N: usize, const K: usize, const V: usize, H> UnsafeUnpin for FixedMap<'a, N, K, V, H>
where &'a mut [MaybeUninit<([u8; K], [u8; V])>]: UnsafeUnpin, &'a mut [u8]: UnsafeUnpin, H: UnsafeUnpin,

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.