infotheory/backends/
sparse_match.rs

1use crate::backends::match_model::MatchModel;
2
3#[derive(Clone, Debug)]
4/// Gapped/sparse match predictor wrapper over [`MatchModel`].
5pub struct SparseMatchModel {
6    inner: MatchModel,
7}
8
9impl SparseMatchModel {
10    /// Create a sparse match model with configurable gap range and mixing behavior.
11    pub fn new(
12        hash_bits: usize,
13        min_len: usize,
14        max_len: usize,
15        gap_min: usize,
16        gap_max: usize,
17        base_mix: f64,
18        confidence_scale: f64,
19    ) -> Self {
20        Self {
21            inner: MatchModel::new(
22                hash_bits,
23                min_len,
24                max_len,
25                gap_min,
26                gap_max,
27                base_mix,
28                confidence_scale,
29            ),
30        }
31    }
32
33    /// Fill `out` with the current normalized byte PDF.
34    pub fn fill_pdf(&mut self, out: &mut [f64; 256]) {
35        self.inner.fill_pdf(out);
36    }
37
38    /// Borrow the current normalized byte PDF.
39    pub fn pdf(&mut self) -> &[f64; 256] {
40        self.inner.pdf()
41    }
42
43    /// Borrow the cumulative distribution derived from the current PDF.
44    pub fn cdf(&mut self) -> &[f64; 257] {
45        self.inner.cdf()
46    }
47
48    /// Return `ln(max(P(symbol), min_prob))`.
49    pub fn log_prob(&mut self, symbol: u8, min_prob: f64) -> f64 {
50        self.inner.log_prob(symbol, min_prob)
51    }
52
53    /// Observe one symbol and update sparse-match statistics.
54    pub fn update(&mut self, symbol: u8) {
55        self.inner.update(symbol);
56    }
57
58    /// Reset only conditioning history, preserving learned tables.
59    pub fn reset_history(&mut self) {
60        self.inner.reset_history();
61    }
62
63    /// Advance history without updating learned sparse-match tables.
64    pub fn update_history_only(&mut self, symbol: u8) {
65        self.inner.update_history_only(symbol);
66    }
67}