struct InodeLruCache {
map: HashMap<u32, u32>,
nodes: HashMap<u32, InodeLruNode>,
head: Option<u32>,
tail: Option<u32>,
next_id: u32,
max_size: usize,
hits: u64,
misses: u64,
access_counter: u64,
}Expand description
O(1) LRU cache implementation for inodes using HashMap + doubly-linked list
Fields§
§map: HashMap<u32, u32>Map from inode number to node ID
nodes: HashMap<u32, InodeLruNode>Storage for all nodes
head: Option<u32>Head of doubly-linked list (most recently used)
tail: Option<u32>Tail of doubly-linked list (least recently used)
next_id: u32Next available node ID
max_size: usizeMaximum cache size
hits: u64Cache statistics
misses: u64§access_counter: u64Access counter for approximate LRU
Implementations§
Source§impl InodeLruCache
impl InodeLruCache
fn new(max_size: usize) -> Self
Sourcefn move_to_head(&mut self, node_id: u32)
fn move_to_head(&mut self, node_id: u32)
O(1) move node to head of LRU list
Sourcefn remove_tail(&mut self)
fn remove_tail(&mut self)
O(1) remove tail (LRU) node
Sourcefn remove_node(&mut self, node_id: u32)
fn remove_node(&mut self, node_id: u32)
O(1) remove node completely
Sourcefn remove_node_from_list(&mut self, node_id: u32)
fn remove_node_from_list(&mut self, node_id: u32)
O(1) remove node from doubly-linked list (but keep in nodes map)
fn len(&self) -> usize
Sourcefn get_stats(&self) -> (u64, u64, usize)
fn get_stats(&self) -> (u64, u64, usize)
Get cache statistics for debugging and performance analysis
Sourcefn print_stats(&self, cache_name: &str)
fn print_stats(&self, cache_name: &str)
Print cache statistics