Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
In [2]:
:timing
:sccache 1
:dep lru = "0.10.0"
Out[2]:
Out[2]:
In [3]:
use lru::LruCache;
use std::num::NonZeroUsize;
Out[3]:
In [5]:
let mut cache: LruCache<u64, &str> = LruCache::new(NonZeroUsize::new(2).unwrap());
Out[5]:
In [6]:
cache.put(1, "a")
Out[6]:
Out[6]:
In [7]:
cache.put(2, "b")
Out[7]:
Out[7]:
In [8]:
cache
Out[8]:
Out[8]:
In [9]:
cache.put(2, "beta")
Out[9]:
Out[9]:
In [11]:
cache.put(3, "hello")
Out[11]:
Out[11]:
In [12]:
cache
Out[12]:
Out[12]:
In [13]:
cache.get(&1)
Out[13]:
Out[13]:
In [14]:
cache.get(&2)
Out[14]:
Out[14]:
In [15]:
cache.get(&3)
Out[15]:
Out[15]:
In [ ]: