lfu

Crates.iolfu
lib.rslfu
version0.2.5
sourcesrc
created_at2020-05-06 22:16:35.827861
updated_at2020-06-22 00:09:52.458772
descriptionAn LFU cache implementation
homepage
repositoryhttps://github.com/NavyaZaveri/lfu-cache
max_upload_size
id238348
size10,033
Navya (NavyaZaveri)

documentation

https://docs.rs/lfu

README

lfu-cache

A rust implementation of a Least Frequently Used (LFU) cache.

It supports insertions and retrievals, both of which are performed in constant time. In the event of tie between multiple least frequently used entries, the least recently used entry is evicted.

Usage:

 extern crate lfu;
 use lfu::LFUCache;

 fn main() {
     let mut lfu = LFUCache::new(2).unwrap(); //initialize an lfu with a maximum capacity of 2 entries
     lfu.set(2, 2);
     lfu.set(3, 3);
     lfu.set(3, 30);
    
    
    //We're at fully capacity. First purge (2,2) since it's the least-frequently-used entry, then insert the current entry
     lfu.set(4,4); 
    
     assert_eq!(lfu.get(&2), None);
     assert_eq!(lfu.get(&3), Some(&30));
}

Install

https://crates.io/crates/lfu

Commit count: 53

cargo fmt