High-performance cache policies and supporting data structures.
Feature: policy-clock-pro
Improve Clock’s scan behavior by tracking hot/cold classification and ghost entries using Clock-style hands.
Maintain three conceptual groups:
Clock hands circulate and adjust status; sequential scans churn through cold pages rather than evicting hot pages.
Implementation uses:
index: FxHashMap<K, usize> mapping keys to slot index in entries bufferentries: Vec<Option<Entry<K, V>>> circular buffer of resident pages
key, value, status (Hot/Cold), referenced bitghost: Vec<Option<GhostEntry<K>>> circular buffer of ghost keysghost_index: FxHashMap<K, usize> for O(1) ghost lookuphand_cold: sweeps for cold page evictionhand_hot: sweeps for hot page demotion (used inline during eviction)ghost_hand: position for next ghost insertiontarget_hot_ratio: adaptive ratio (starts at 0.5, increases on ghost hits)get(key):
referenced = true, return valueinsert(key, value):
referenced = trueevict():
hand_cold:
max_hot limit) → demote to Cold or clear referencedClock-PRO resists scan pollution because:
| Operation | Time | Notes |
|---|---|---|
get |
O(1) | Hash lookup + bit operation |
insert |
O(1)* | *Amortized; eviction may sweep |
contains |
O(1) | Hash lookup only |
remove |
O(1) | Hash lookup + clear slot |
ClockProCache: Not thread-safe, designed for single-threaded use