Skip to content

Commit

Permalink
offset in last window slice is calculated differently
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Nov 18, 2024
1 parent f0707cb commit f60e704
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/encoding/match_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ impl<'data> MatchGenerator<'data> {

if match_len >= MIN_MATCH_LEN {
let literals = &last_entry.data[self.last_idx_in_sequence..self.suffix_idx];
let offset = match_entry.base_offset - match_index + self.suffix_idx;
let offset = if is_last {
self.suffix_idx - match_index
} else {
match_entry.base_offset - match_index + self.suffix_idx
};
sequence = Some(Sequence::Triple {
literals,
offset,
Expand Down Expand Up @@ -269,4 +273,14 @@ fn matches() {
}
);
assert!(matcher.next_sequence().is_none());
matcher.add_data(&[0, 0, 11, 13, 15, 17, 19, 11, 13, 15, 17, 19]);
assert_eq!(
matcher.next_sequence().unwrap(),
Sequence::Triple {
literals: &[0, 0, 11, 13, 15, 17, 19,],
offset: 5,
match_len: 5
}
);
assert!(matcher.next_sequence().is_none());
}

0 comments on commit f60e704

Please sign in to comment.