use super::*;
use crate::error::Error;
use alloc::collections::btree_map::Entry;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
pub struct PerfectByteHashMapCacheOwned {
data: BTreeMap<Vec<u8>, PerfectByteHashMap<Vec<u8>>>,
}
impl PerfectByteHashMapCacheOwned {
pub fn new_empty() -> Self {
Self {
data: BTreeMap::new(),
}
}
pub fn try_get_or_insert(&mut self, keys: Vec<u8>) -> Result<&PerfectByteHashMap<[u8]>, Error> {
let mut_phf = match self.data.entry(keys) {
Entry::Vacant(entry) => {
let value = PerfectByteHashMap::try_new(entry.key())?;
entry.insert(value)
}
Entry::Occupied(entry) => entry.into_mut(),
};
Ok(mut_phf.as_borrowed())
}
}