This repository contains a fast and flexible LRU map.
lru
crate, and with less memory overhead.indexmap
,
but with added support for O(1) removals without changing the element order (where indexmap
only supports O(n) non-perturbing removals).no_std
.```rust use schnellru::{LruMap, ByLength}; let mut map = LruMap::new(ByLength::new(3));
// Insert three elements. map.insert(1, "one"); map.insert(2, "two"); map.insert(3, "three"); assert_eq!(map.len(), 3);
// Access the middle one. assert_eq!(*map.get(&1).unwrap(), "one");
// Insert a fourth element. // This will automatically pop the least recently accessed one. map.insert(4, "four");
// Still the same number of elements. assert_eq!(map.len(), 3);
// And this is the one which was removed. assert!(map.peek(&2).is_none()); ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.