Skip to main content

dtrees_rs/caching/
mod.rs

1//! The cache of subproblems used by DL8.5.
2//!
3//! A subproblem is identified by the itemset of tests leading to it, sorted,
4//! so that paths testing the same features in a different order share one
5//! entry.
6
7use crate::caching::entry::CacheEntryUpdater;
8
9mod entry;
10mod helpers;
11mod trie;
12pub use entry::CacheEntry;
13pub use helpers::{CacheKey, Index, SearchPath};
14pub use trie::Trie;
15
16/// A cache of subproblems keyed by sorted itemsets.
17pub trait Caching {
18    /// Clears the cache and creates the root entry.
19    fn init(&mut self) -> Index;
20
21    /// Index of the root entry.
22    fn root_index(&mut self) -> Index;
23
24    /// The root entry.
25    fn root(&self) -> Option<&CacheEntry>;
26
27    /// Finds the entry of the sorted itemset `key`, creating it if needed.
28    /// The index is `New` for an entry that has not been evaluated yet.
29    fn insert(&mut self, key: &[usize]) -> Index;
30
31    /// The entry for `key`.
32    fn node(&self, key: &CacheKey) -> Option<&CacheEntry>;
33
34    /// Whether the cache has an entry for `key`.
35    fn contains(&self, key: &CacheKey) -> bool;
36
37    /// An updater for the root entry.
38    fn update_root(&mut self) -> Option<CacheEntryUpdater<'_>>;
39
40    /// An updater for the entry of `key`.
41    fn update_node(&mut self, key: &CacheKey) -> Option<CacheEntryUpdater<'_>>;
42
43    /// Number of entries.
44    fn size(&self) -> usize;
45
46    /// Whether the cache has no entry.
47    fn is_empty(&self) -> bool;
48}