use std::cell::RefCell;
use std::collections::HashMap;
use crate::testing::fdr::config::{Failure, Trace};
use crate::testing::fdr::explorer::MemoizationCache;
pub struct DefaultCache {
traces_cache: RefCell<HashMap<u64, (Vec<Trace>, bool)>>,
failures_cache: RefCell<HashMap<u64, (Vec<Failure>, bool)>>,
divergences_cache: RefCell<HashMap<u64, (Vec<Trace>, bool)>>,
}
impl DefaultCache {
pub fn new() -> Self {
Self {
traces_cache: RefCell::new(HashMap::new()),
failures_cache: RefCell::new(HashMap::new()),
divergences_cache: RefCell::new(HashMap::new()),
}
}
}
impl Default for DefaultCache {
fn default() -> Self {
Self::new()
}
}
impl MemoizationCache for DefaultCache {
fn get_cached_traces(&self, structure: u64) -> Option<(Vec<Trace>, bool)> {
self.traces_cache.borrow().get(&structure).cloned()
}
fn cache_traces(&mut self, structure: u64, traces: Vec<Trace>, complete: bool) {
self.traces_cache.borrow_mut().insert(structure, (traces, complete));
}
fn get_cached_failures(&self, structure: u64) -> Option<(Vec<Failure>, bool)> {
self.failures_cache.borrow().get(&structure).cloned()
}
fn cache_failures(&mut self, structure: u64, failures: Vec<Failure>, complete: bool) {
self.failures_cache.borrow_mut().insert(structure, (failures, complete));
}
fn get_cached_divergences(&self, structure: u64) -> Option<(Vec<Trace>, bool)> {
self.divergences_cache.borrow().get(&structure).cloned()
}
fn cache_divergences(&mut self, structure: u64, divergences: Vec<Trace>, complete: bool) {
self.divergences_cache.borrow_mut().insert(structure, (divergences, complete));
}
}