FabricHashMap

Struct FabricHashMap 

Source
pub struct FabricHashMap<K, V> { /* private fields */ }
Expand description

A hash map stored in leased fabric memory with open addressing.

Keys and values are serialized via postcard into fixed-size slots. Collision resolution uses linear probing. The map owns its MemLease and releases it on drop.

The maximum load factor is 75%. Inserting beyond this threshold returns FabricError::CapacityExceeded.

§Type parameters

  • K: Key type. Must implement Serialize + DeserializeOwned + PartialEq.
  • V: Value type. Must implement Serialize + DeserializeOwned.

§Example

use grafos_collections::map::FabricHashMap;
use grafos_std::mem::MemBuilder;

let mut map: FabricHashMap<u32, u32> = FabricHashMap::with_capacity(64, 8, 8)?;
map.insert(&1, &100)?;
map.insert(&2, &200)?;
assert_eq!(map.get(&1)?, Some(100));
assert_eq!(map.remove(&2)?, Some(200));

Implementations§

Source§

impl<K: Serialize + DeserializeOwned + PartialEq, V: Serialize + DeserializeOwned> FabricHashMap<K, V>

Source

pub fn new( lease: MemLease, key_stride: usize, val_stride: usize, ) -> Result<Self>

Create a new hash map taking ownership of the given lease.

key_stride and val_stride are the maximum serialized sizes (in bytes) for keys and values respectively. The number of buckets is derived from (arena_size - 32) / bucket_size.

All buckets are zeroed (marked empty) during construction.

§Errors

Returns FabricError::CapacityExceeded if the arena is too small to hold the 32-byte header plus at least one bucket.

Source

pub fn from_lease(lease: MemLease) -> Result<Self>

Recover a hash map from an existing memory lease.

Reads the 32-byte header to discover count, bucket_count, key_stride, and val_stride. This enables crash recovery: a replacement tasklet can call MemBuilder::attach(lease_id) and then FabricHashMap::from_lease() to reconnect to a surviving hot-tier hash map without re-inserting data.

§Errors
Source

pub fn with_capacity( bucket_count: usize, key_stride: usize, val_stride: usize, ) -> Result<Self>

Create a new hash map by acquiring a lease sized for bucket_count buckets.

This is a convenience constructor that acquires a lease via MemBuilder and then calls FabricHashMap::new.

§Errors

Returns FabricError::CapacityExceeded if the host cannot provide an arena large enough.

Source

pub fn insert(&mut self, key: &K, value: &V) -> Result<Option<V>>

Insert a key-value pair. Returns the previous value if the key already existed.

If the key is already present, the value is overwritten and the old value is returned as Some(old). If the key is new, returns None.

§Errors
Source

pub fn get(&self, key: &K) -> Result<Option<V>>

Look up a value by key.

Returns Some(value) if the key exists, None otherwise.

§Errors

Returns FabricError::IoError if serialization or remote read fails.

Source

pub fn remove(&mut self, key: &K) -> Result<Option<V>>

Remove a key-value pair. Returns the removed value if the key existed.

The bucket is tombstoned rather than cleared to preserve the linear probing chain. Tombstoned buckets are reused by subsequent inserts.

§Errors

Returns FabricError::IoError if serialization or remote I/O fails.

Source

pub fn contains_key(&self, key: &K) -> Result<bool>

Returns true if the map contains the given key.

Equivalent to self.get(key)?.is_some().

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

pub fn lease_id(&self) -> u128

Returns the lease ID of the memory lease for external renewal management (e.g. via [grafos_leasekit::RenewalManager]).

Source

pub fn expires_at_unix_secs(&self) -> u64

Returns the expiry time (unix seconds) of the memory lease for external renewal management.

Source

pub fn iter(&self) -> FabricHashMapIter<'_, K, V>

Returns an iterator over all key-value pairs.

The iterator scans all buckets, skipping empty and tombstoned slots. Iteration order is determined by bucket layout, not insertion order.

Auto Trait Implementations§

§

impl<K, V> Freeze for FabricHashMap<K, V>

§

impl<K, V> !RefUnwindSafe for FabricHashMap<K, V>

§

impl<K, V> !Send for FabricHashMap<K, V>

§

impl<K, V> !Sync for FabricHashMap<K, V>

§

impl<K, V> Unpin for FabricHashMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for FabricHashMap<K, V>

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.