pub struct S3FifoWidthCache { /* private fields */ }Expand description
Width cache backed by S3-FIFO eviction (bd-l6yba.2).
Drop-in replacement for WidthCache that uses the scan-resistant
S3-FIFO eviction policy instead of LRU. This protects frequently-used
width entries from being evicted by one-time scan patterns (e.g. when a
large block of new text scrolls past).
Uses the same 64-bit FxHash keying as WidthCache with a secondary
FNV fingerprint for collision detection.
Implementations§
Source§impl S3FifoWidthCache
impl S3FifoWidthCache
Sourcepub fn with_default_capacity() -> Self
pub fn with_default_capacity() -> Self
Create a new cache with the default capacity (4096 entries).
Sourcepub fn get_or_compute(&mut self, text: &str) -> usize
pub fn get_or_compute(&mut self, text: &str) -> usize
Get cached width or compute and cache it.
Sourcepub fn get_or_compute_with<F>(&mut self, text: &str, compute: F) -> usize
pub fn get_or_compute_with<F>(&mut self, text: &str, compute: F) -> usize
Get cached width or compute using a custom function.
Sourcepub fn contains(&self, text: &str) -> bool
pub fn contains(&self, text: &str) -> bool
Check if a key is in the cache.
Keys on the 64-bit hash only (like WidthCache::contains): the
fingerprint is not verified here, so a colliding string reports
true even though get_or_compute would treat it as a miss.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset statistics.