Skip to main content

Module width_cache

Module width_cache 

Source
Expand description

LRU width cache for efficient text measurement.

Text width calculation is a hot path (called every render frame). This cache stores computed widths to avoid redundant Unicode width calculations for repeated strings.

§Example

use ftui_text::WidthCache;

let mut cache = WidthCache::new(1000);

// First call computes width
let width = cache.get_or_compute("Hello, world!");
assert_eq!(width, 13);

// Second call hits cache
let width2 = cache.get_or_compute("Hello, world!");
assert_eq!(width2, 13);

// Check stats
let stats = cache.stats();
assert_eq!(stats.hits, 1);
assert_eq!(stats.misses, 1);

Structs§

CacheStats
Statistics about cache performance.
CountMinSketch
Count-Min Sketch for approximate frequency estimation.
Doorkeeper
1-bit Bloom filter used as a doorkeeper to filter one-hit wonders.
S3FifoWidthCache
Width cache backed by S3-FIFO eviction (bd-l6yba.2).
TinyLfuWidthCache
Width cache using W-TinyLFU admission policy.
WidthCache
LRU cache for text width measurements.

Constants§

DEFAULT_CACHE_CAPACITY
Default cache capacity.

Functions§

fingerprint_hash
Compute a secondary fingerprint hash for collision guard.
tinylfu_admit
Evaluate the TinyLFU admission rule.