Last active
March 21, 2022 03:40
-
-
Save jayhuang75/5af21d5bfeca1b2552bf3142c06b9ca4 to your computer and use it in GitHub Desktop.
lfu_get_evict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // return a ref of the most-recently-used entry | |
| pub fn get(&mut self, key: &'a str) -> Option<&T> where T: Debug{ | |
| self.update_freq_node(key); | |
| self.by_key.get(key).map(|e| &e.val) | |
| } | |
| // evict the least freq used | |
| fn evict(&mut self) { | |
| let least_freq_node = self.freq_node.get_mut(&self.least_freq_node).unwrap(); | |
| let least_freq_entry= least_freq_node.pop_front().unwrap(); | |
| self.by_key.remove(least_freq_entry); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment