use std::collections::BTreeMap;
use core::cmp::Ord;
use crate::{
container::{ContainerClear, ContainerLen, ContainerRemove, SparseContainer},
GenericCache,
};
pub type BTreeCache<'f, I, O> = GenericCache<'f, BTreeMap<I, O>>;
impl<I, O> SparseContainer for BTreeMap<I, O>
where
I: Ord,
{
type Input = I;
type Output = O;
fn has(&self, input: &Self::Input) -> bool {
self.contains_key(input)
}
fn get(&self, input: &Self::Input) -> Option<&Self::Output> {
self.get(input)
}
fn put(&mut self, input: Self::Input, output: Self::Output) -> &Self::Output {
self.entry(input).or_insert(output)
}
}
impl<I, O> ContainerLen for BTreeMap<I, O>
where
I: Ord,
{
fn len(&self) -> usize {
self.len()
}
}
impl<I, O> ContainerClear for BTreeMap<I, O>
where
I: Ord,
{
fn clear(&mut self) {
self.clear()
}
}
impl<I, O> ContainerRemove for BTreeMap<I, O>
where
I: Ord,
{
fn remove(&mut self, input: &Self::Input) -> Option<Self::Output> {
self.remove(input)
}
}