use std::collections::HashMap;
pub struct WorkingSetCache {
capacity: usize,
cache: HashMap<u32, Vec<f32>>,
}
impl WorkingSetCache {
pub fn new(capacity: usize) -> Self {
Self {
capacity,
cache: HashMap::new(),
}
}
pub fn get(&self, id: u32) -> Option<&Vec<f32>> {
self.cache.get(&id)
}
pub fn insert(&mut self, id: u32, vector: Vec<f32>) {
if self.cache.len() >= self.capacity {
if let Some(&first_key) = self.cache.keys().next() {
self.cache.remove(&first_key);
}
}
self.cache.insert(id, vector);
}
pub fn clear(&mut self) {
self.cache.clear();
}
}