pub struct Recency<K> { /* private fields */ }Expand description
A recency queue with lazy deletion.
A hit appends the key with a fresh stamp in constant time and leaves its
old position behind as a ghost. The caller stores the returned stamp on
its own entry and answers is_live from it, so this holds no second copy
of the entry table and never duplicates whatever hangs off a key.
Eviction skips ghosts as it pops them, and ghosts are dropped in bulk
once they outnumber the live entries they shadow — amortized constant,
like a vector reallocation. Nothing is scheduled.
Implementations§
Source§impl<K: Clone> Recency<K>
impl<K: Clone> Recency<K>
Sourcepub fn touch(&mut self, key: &K) -> u64
pub fn touch(&mut self, key: &K) -> u64
Records an access and returns the stamp the caller must store on its entry before calling anything else here: until the entry carries it, the position just appended reads as a ghost.
Stamps start at 1, so an entry that has never been touched can carry 0 and read as a ghost.
Sourcepub fn pop_oldest(&mut self, is_live: impl FnMut(&K, u64) -> bool) -> Option<K>
pub fn pop_oldest(&mut self, is_live: impl FnMut(&K, u64) -> bool) -> Option<K>
Removes and returns the least recently used live key.
None means the queue holds no live position at all, so an eviction
loop must stop: popping again cannot make progress.
Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for Recency<K>
impl<K> RefUnwindSafe for Recency<K>where
K: RefUnwindSafe,
impl<K> Send for Recency<K>where
K: Send,
impl<K> Sync for Recency<K>where
K: Sync,
impl<K> Unpin for Recency<K>where
K: Unpin,
impl<K> UnsafeUnpin for Recency<K>
impl<K> UnwindSafe for Recency<K>where
K: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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