Crate lru [−] [src]
An implementation of a LRU cache. The cache supports get
, put
, and remove
operations, all of which are O(1). This crate was heavily influenced by the
LRU Cache implementation in an earlier version of Rust's std::collections crate.
Example
extern crate lru; use lru::LruCache; fn main() { let mut cache = LruCache::new(2); cache.put("apple", "red"); cache.put("banana", "yellow"); assert_eq!(*cache.get(&"apple").unwrap(), "red"); assert_eq!(*cache.get(&"banana").unwrap(), "yellow"); assert!(cache.get(&"pear").is_none()); cache.put("pear", "green"); assert_eq!(*cache.get(&"pear").unwrap(), "green"); assert_eq!(*cache.get(&"banana").unwrap(), "yellow"); assert!(cache.get(&"apple").is_none()); }
Structs
LruCache |
An LRU Cache |