use std::hash::Hash;
use hashlink::LruCache;
use crate::Cache;
pub struct Lru<K: Hash + Eq, V>(pub LruCache<K, V>);
impl<K: Hash + Eq, V> Lru<K, V> {
#[inline(always)]
pub fn new(cap: usize) -> Self {
Self(LruCache::new(cap.max(1)))
}
}
impl<K: Hash + Eq, V> Cache<K, V> for Lru<K, V> {
#[inline(always)]
fn get(&mut self, key: &K) -> Option<&V> {
self.0.get(key)
}
#[inline(always)]
fn set(&mut self, key: K, val: V) {
self.0.insert(key, val);
}
#[inline(always)]
fn rm(&mut self, key: &K) {
self.0.remove(key);
}
}