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 a VecDeque 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>
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>
impl<T, const N: usize> UnwindSafe for FifoCache<T, N>where
T: UnwindSafe,
Blanket Implementations§
impl<T> Allocation for T
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