Skip to content

Commit

Permalink
use slices instead of fixed size arrays as key for match generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Borcherding committed Nov 25, 2024
1 parent 3fd7cb2 commit 04caa1d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/encoding/match_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const MIN_MATCH_LEN: usize = 5;

struct WindowEntry<'data> {
data: &'data [u8],
suffixes: HashMap<[u8; MIN_MATCH_LEN], usize>,
suffixes: HashMap<&'data [u8], usize>,
base_offset: usize,
}

Expand Down Expand Up @@ -75,8 +75,7 @@ impl<'data> MatchGenerator<'data> {
});
}

let mut key = [0u8; MIN_MATCH_LEN];
key.copy_from_slice(&data_slice[..MIN_MATCH_LEN]);
let key = &data_slice[..MIN_MATCH_LEN];

for (match_entry_idx, match_entry) in self.window.iter().enumerate() {
let is_last = match_entry_idx == self.window.len() - 1;
Expand Down Expand Up @@ -126,6 +125,7 @@ impl<'data> MatchGenerator<'data> {
self.last_idx_in_sequence = self.suffix_idx;
} else {
let last_entry = self.window.last_mut().unwrap();
let key = &last_entry.data[..MIN_MATCH_LEN];
if !last_entry.suffixes.contains_key(&key) {
last_entry.suffixes.insert(key, self.suffix_idx);
}
Expand All @@ -143,8 +143,7 @@ impl<'data> MatchGenerator<'data> {
}
let last_idx = usize::min(idx, last_entry.data.len() - MIN_MATCH_LEN);
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]);
let key = &last_entry.data[idx..idx + MIN_MATCH_LEN];
if !last_entry.suffixes.contains_key(&key) {
last_entry.suffixes.insert(key, idx);
}
Expand Down

0 comments on commit 04caa1d

Please sign in to comment.