SIEVE Cache (Rust)
Topics: cache eviction, index arena, SIEVE
Problem
Implement the SIEVE eviction algorithm (Zhang et al., NSDI 2024) — simpler than LRU, with a
better hit rate. It's a single FIFO-ordered doubly-linked list where each entry has a visited
bit, plus a hand that scans for a victim.
pub struct Sieve { /* … */ }
impl Sieve {
pub fn new(capacity: usize) -> Self;
pub fn get(&mut self, key: i32) -> Option<i32>;
pub fn put(&mut self, key: i32, val: i32);
pub fn len(&self) -> usize;
}
- New entries are inserted at the head (newest) with their visited bit clear.
get (a hit) sets the entry's visited bit — its "second chance" — and does not move it.
- On a full
put, evict: start at the hand (or the tail/oldest on the first eviction) and
scan toward the head, clearing any set visited bit you pass; evict the first entry whose bit is
already clear. The hand then advances to the next candidate (toward the head) and keeps that
position for the next eviction.
- Updating an existing key refreshes its value and marks it visited.
put 1,2,3 (cap 3); get(1); put(4) → evicts 2, not 1 (1 had its bit set)
The list is held in an index arena (a Vec<Node> + a free list) so links are O(1) without raw
pointers. The arena plumbing (alloc, insert_at_head, unlink) is provided; you implement get,
put, and evict.
Grading
Your solution.rs is compiled together with a trusted tests.rs (which include!s it) using
rustc --test. Only solution.rs is yours to edit.
Sign in to submit your solution.