Module lru_cache

Module lru_cache 

Source
Expand description

LRU Cache (Generic, Hashable, Production-Grade)

A Least Recently Used (LRU) cache with O(1) get and put operations.

§Type Parameters

  • K: The key type. Must implement Eq + Hash + Clone.
  • V: The value type. Must implement Clone.

§Example

use pofk_algorithm::set_algorithms::lru_cache::LruCache;
let mut cache = LruCache::new(2);
cache.put(1, "a");
cache.put(2, "b");
assert_eq!(cache.get(&1), Some("a"));
cache.put(3, "c"); // Evicts key 2
assert_eq!(cache.get(&2), None);
assert_eq!(cache.get(&3), Some("c"));

Structs§

LruCache