Skip to main content

MemHashIndex

Struct MemHashIndex 

Source
pub struct MemHashIndex { /* private fields */ }
Expand description

Memory-based concurrent hash index

This is the main index structure that maps keys to their latest addresses in the hybrid log. It uses DashMap for thread-safe concurrent access.

Implementations§

Source§

impl MemHashIndex

Source

pub fn new(epoch: SharedEpochManager) -> Self

Create a new memory hash index

Source

pub fn with_capacity(capacity: usize, epoch: SharedEpochManager) -> Self

Create a new memory hash index with specified capacity

Source

pub fn find(&self, key: &Key) -> Option<Address>

Find the address for a given key Returns None if the key is not found

Source

pub fn insert(&self, key: Key, address: Address)

Insert or update a key-address mapping This will overwrite any existing mapping for the key

Source

pub fn insert_if_not_exists(&self, key: Key, address: Address) -> bool

Insert a key-address mapping only if the key doesn’t exist Returns true if the insertion was successful, false if key already exists

Source

pub fn update_if_exists( &self, key: &Key, old_address: Address, new_address: Address, ) -> bool

Update an existing key-address mapping using compare-and-swap Returns true if the update was successful

Source

pub fn remove(&self, key: &Key) -> Option<Address>

Remove a key from the index Returns the old address if the key was found and removed

Source

pub fn remove_if_address(&self, key: &Key, expected_address: Address) -> bool

Remove a key only if it currently maps to the specified address This is useful for conditional removals during garbage collection

Source

pub fn len(&self) -> usize

Get the number of entries in the index

Source

pub fn is_empty(&self) -> bool

Check if the index is empty

Source

pub fn clear(&self)

Clear all entries from the index

Source

pub fn for_each<F>(&self, f: F)
where F: FnMut(&Key, Address),

Iterate over all key-address pairs The provided closure will be called for each entry

Source

pub fn collect_matching<F>(&self, predicate: F) -> Vec<(Key, Address)>
where F: Fn(&Key, Address) -> bool,

Iterate over entries and collect those that match a predicate This is useful for operations like garbage collection

Source

pub fn remove_matching<F>(&self, predicate: F) -> usize
where F: Fn(&Key, Address) -> bool,

Remove entries that match a predicate Returns the number of entries removed

Source

pub fn snapshot(&self) -> Vec<(Key, Address)>

Create a snapshot of the current index state This is useful for checkpointing

Source

pub fn restore_from_snapshot(&self, snapshot: Vec<(Key, Address)>)

Restore the index from a snapshot This will clear the current index and load the snapshot data

Source

pub fn memory_usage(&self) -> IndexMemoryStats

Get memory usage statistics

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.