Skip to main content

SieveCache

Struct SieveCache 

Source
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>

Source

pub fn new(capacity: usize) -> Self

Source

pub fn get(&mut self, key: u64) -> Option<&V>

Look up a key. If found, set visited=true and return reference.

Source

pub fn get_mut(&mut self, key: u64) -> Option<&mut V>

Look up a key. If found, set visited=true and return mutable reference.

Source

pub fn contains(&self, key: u64) -> bool

Check if a key exists without marking visited.

Source

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).

Source

pub fn set_dirty(&mut self, key: u64)

Mark an entry as dirty (pinned, not evictable).

Source

pub fn clear_dirty(&mut self, key: u64)

Clear dirty flag on an entry (after flush).

Source

pub fn is_dirty(&self, key: u64) -> bool

Check if an entry is dirty.

Source

pub fn dirty_entries(&self) -> impl Iterator<Item = (u64, &V)>

Iterate over all dirty entries. Returns (key, &value) pairs.

Source

pub fn dirty_entries_mut(&mut self) -> impl Iterator<Item = (u64, &mut V)>

Iterate mutably over all dirty entries.

Source

pub fn clear_all_dirty(&mut self)

Clear all dirty flags (after commit).

Source

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

Remove an entry by key. Returns the value if present.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Source

pub fn dirty_count(&self) -> usize

Count dirty entries.

Source

pub fn clear(&mut self)

Remove all entries from the cache.

Auto Trait Implementations§

§

impl<V> Freeze for SieveCache<V>

§

impl<V> RefUnwindSafe for SieveCache<V>
where V: RefUnwindSafe,

§

impl<V> Send for SieveCache<V>
where V: Send,

§

impl<V> Sync for SieveCache<V>
where V: Sync,

§

impl<V> Unpin for SieveCache<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for SieveCache<V>

§

impl<V> UnwindSafe for SieveCache<V>
where V: UnwindSafe,

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

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V