1
2
3
4
5
6
7
8
9
10
11
12
13
use aurora_engine_types::BTreeMap;

/// A naive cache storing all key-value pairs it learns about.
#[derive(Default)]
pub struct FullCache<K, V> {
    inner: BTreeMap<K, V>,
}

impl<K: Ord, V> FullCache<K, V> {
    pub fn get_or_insert_with<F: FnOnce() -> V>(&mut self, k: K, f: F) -> &mut V {
        self.inner.entry(k).or_insert_with(f)
    }
}