pub struct SieveCache<V> { /* private fields */ }Expand description
SIEVE eviction cache.
Single FIFO queue with a moving eviction hand and a visited bit. Dirty entries are pinned and never evictable.
O(1) amortized eviction.
Implementations§
Source§impl<V: Default> SieveCache<V>
impl<V: Default> SieveCache<V>
pub fn new(capacity: usize) -> Self
Sourcepub fn get(&mut self, key: u64) -> Option<&V>
pub fn get(&mut self, key: u64) -> Option<&V>
Look up a key. If found, set visited=true and return reference.
Sourcepub fn get_mut(&mut self, key: u64) -> Option<&mut V>
pub fn get_mut(&mut self, key: u64) -> Option<&mut V>
Look up a key. If found, set visited=true and return mutable reference.
Sourcepub fn insert(&mut self, key: u64, value: V) -> Result<Option<(u64, V)>, ()>
pub fn insert(&mut self, key: u64, value: V) -> Result<Option<(u64, V)>, ()>
Insert a value. If cache is full, evict using SIEVE algorithm. Returns None if inserted without eviction, or Some((evicted_key, evicted_value)) if an entry was evicted.
Returns Err(()) if the cache is full and all entries are dirty (pinned).
Sourcepub fn clear_dirty(&mut self, key: u64)
pub fn clear_dirty(&mut self, key: u64)
Clear dirty flag on an entry (after flush).
Sourcepub fn dirty_entries(&self) -> impl Iterator<Item = (u64, &V)>
pub fn dirty_entries(&self) -> impl Iterator<Item = (u64, &V)>
Iterate over all dirty entries. Returns (key, &value) pairs.
Sourcepub fn dirty_entries_mut(&mut self) -> impl Iterator<Item = (u64, &mut V)>
pub fn dirty_entries_mut(&mut self) -> impl Iterator<Item = (u64, &mut V)>
Iterate mutably over all dirty entries.
Sourcepub fn clear_all_dirty(&mut self)
pub fn clear_all_dirty(&mut self)
Clear all dirty flags (after commit).
Sourcepub fn remove(&mut self, key: u64) -> Option<V>
pub fn remove(&mut self, key: u64) -> Option<V>
Remove an entry by key. Returns the value if present.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Sourcepub fn dirty_count(&self) -> usize
pub fn dirty_count(&self) -> usize
Count dirty entries.