pub struct FifoCache<T, const N: usize>{ /* private fields */ }Expand description
A bounded cache that maintains a set of IDs with O(1) lookups.
Uses an ArrayDeque for FIFO ordering and an AHashSet for fast membership checks.
When capacity is exceeded, the oldest entry is automatically evicted.
§Examples
use nautilus_common::cache::fifo::FifoCache;
let mut cache: FifoCache<u32, 3> = FifoCache::new();
cache.add(1);
cache.add(2);
cache.add(3);
assert!(cache.contains(&1));
// Adding beyond capacity evicts the oldest
cache.add(4);
assert!(!cache.contains(&1));
assert!(cache.contains(&4));Zero capacity is a compile-time error:
ⓘ
use nautilus_common::cache::fifo::FifoCache;
// This fails to compile: capacity must be > 0
let cache: FifoCache<u32, 0> = FifoCache::new();Default also enforces non-zero capacity:
ⓘ
use nautilus_common::cache::fifo::FifoCache;
// This also fails to compile
let cache: FifoCache<u32, 0> = FifoCache::default();Implementations§
Source§impl<T, const N: usize> FifoCache<T, N>
impl<T, const N: usize> FifoCache<T, N>
Trait Implementations§
Auto Trait Implementations§
impl<T, const N: usize> Freeze for FifoCache<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for FifoCache<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for FifoCache<T, N>where
T: Send,
impl<T, const N: usize> Sync for FifoCache<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for FifoCache<T, N>where
T: Unpin,
impl<T, const N: usize> UnsafeUnpin for FifoCache<T, N>where
T: UnsafeUnpin,
impl<T, const N: usize> UnwindSafe for FifoCache<T, N>where
T: 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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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 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>
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