Type Definition coca::collections::Inline2WayLruCache
source · [−]pub type Inline2WayLruCache<K, V, H, const N: usize> = CacheTable<K, V, InlineStorage<LruCache2<K, V>, N>, LruCache2<K, V>, H>;
Expand description
A 2-way set-associative cache with a least recently used eviction policy, using an inline array for storage.
Note that the constant generic parameter N
is the number of cache lines,
i.e. caches of this type have capacity for 2 * N
key-value pairs.
Examples
use rustc_hash::FxHasher;
let keys = ["Alice", "Bob", "Charlie", "David", "Eve", "Faythe", "Grace"];
let mut cache = Inline2WayLruCache::<&'static str, usize, BuildHasherDefault<FxHasher>, 3>::new();
assert_eq!(cache.capacity(), 6);
for k in &keys {
cache.insert(k, k.len());
assert_eq!(cache.get(k), Some(&k.len()));
}
let mut remembered = 0;
for k in &keys {
if let Some(len) = cache.get(k) {
assert_eq!(len, &k.len());
remembered += 1;
}
}
assert!(0 < remembered);
assert!(remembered < keys.len());