Skip to content

Commit

Permalink
matcher can now also accept data that doesnt need matches
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Nov 17, 2024
1 parent ddcfa12 commit 96d1430
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/encoding/match_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'data> MatchGenerator<'data> {
fn add_suffixes_till(&mut self, idx: usize) {
let last_entry = self.window.last_mut().unwrap();
let last_idx = usize::min(idx, last_entry.data.len() - MIN_MATCH_LEN);
for idx in self.suffix_idx..last_idx {
for idx in self.suffix_idx..=last_idx {
let mut key = [0u8; MIN_MATCH_LEN];
key.copy_from_slice(&last_entry.data[idx..idx + MIN_MATCH_LEN]);
if !last_entry.suffixes.contains_key(&key) {
Expand All @@ -128,6 +128,11 @@ impl<'data> MatchGenerator<'data> {
}
}

pub(crate) fn add_data_no_matching(&mut self, data: &'data [u8]) {
self.add_data(data);
self.add_suffixes_till(data.len());
self.suffix_idx = data.len();
}
pub(crate) fn add_data(&mut self, data: &'data [u8]) {
assert!(
self.window.is_empty() || self.suffix_idx == self.window.last().unwrap().data.len()
Expand Down Expand Up @@ -250,4 +255,18 @@ fn matches() {
}
);
assert!(matcher.next_sequence().is_none());

matcher.add_data_no_matching(&[1, 3, 5, 7, 9]);
assert!(matcher.next_sequence().is_none());

matcher.add_data(&[1, 3, 5, 7, 9]);
assert_eq!(
matcher.next_sequence().unwrap(),
Sequence::Triple {
literals: &[],
offset: 5,
match_len: 5
}
);
assert!(matcher.next_sequence().is_none());
}

0 comments on commit 96d1430

Please sign in to comment.