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
impl MemHashIndex
Sourcepub fn new(epoch: SharedEpochManager) -> Self
pub fn new(epoch: SharedEpochManager) -> Self
Create a new memory hash index
Sourcepub fn with_capacity(capacity: usize, epoch: SharedEpochManager) -> Self
pub fn with_capacity(capacity: usize, epoch: SharedEpochManager) -> Self
Create a new memory hash index with specified capacity
Sourcepub fn find(&self, key: &Key) -> Option<Address>
pub fn find(&self, key: &Key) -> Option<Address>
Find the address for a given key Returns None if the key is not found
Sourcepub fn insert(&self, key: Key, address: Address)
pub fn insert(&self, key: Key, address: Address)
Insert or update a key-address mapping This will overwrite any existing mapping for the key
Sourcepub fn insert_if_not_exists(&self, key: Key, address: Address) -> bool
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
Sourcepub fn update_if_exists(
&self,
key: &Key,
old_address: Address,
new_address: Address,
) -> bool
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
Sourcepub fn remove(&self, key: &Key) -> Option<Address>
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
Sourcepub fn remove_if_address(&self, key: &Key, expected_address: Address) -> bool
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
Sourcepub fn for_each<F>(&self, f: F)
pub fn for_each<F>(&self, f: F)
Iterate over all key-address pairs The provided closure will be called for each entry
Sourcepub fn collect_matching<F>(&self, predicate: F) -> Vec<(Key, Address)>
pub fn collect_matching<F>(&self, predicate: F) -> Vec<(Key, Address)>
Iterate over entries and collect those that match a predicate This is useful for operations like garbage collection
Sourcepub fn remove_matching<F>(&self, predicate: F) -> usize
pub fn remove_matching<F>(&self, predicate: F) -> usize
Remove entries that match a predicate Returns the number of entries removed
Sourcepub fn snapshot(&self) -> Vec<(Key, Address)>
pub fn snapshot(&self) -> Vec<(Key, Address)>
Create a snapshot of the current index state This is useful for checkpointing
Sourcepub fn restore_from_snapshot(&self, snapshot: Vec<(Key, Address)>)
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
Sourcepub fn memory_usage(&self) -> IndexMemoryStats
pub fn memory_usage(&self) -> IndexMemoryStats
Get memory usage statistics
Auto Trait Implementations§
impl !RefUnwindSafe for MemHashIndex
impl !UnwindSafe for MemHashIndex
impl Freeze for MemHashIndex
impl Send for MemHashIndex
impl Sync for MemHashIndex
impl Unpin for MemHashIndex
impl UnsafeUnpin for MemHashIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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