Skip to content

Commit

Permalink
Add missing overlap at match on end of input extending into new window
Browse files Browse the repository at this point in the history
fixes #42
  • Loading branch information
oyvindln committed Feb 4, 2020
1 parent 2385f2a commit 06efadd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lz77.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ fn add_to_hash_table(
/// `ProcessStatus::BufferFull($pos)` if the buffer is full after writing.
///
/// `pos` should indicate the byte to start at in the next call to `process_chunk`,
/// `is_hashed` should be set to true of the byte at pos has been added to the hash chain.
macro_rules! write_literal {
($w:ident, $byte:expr, $pos:expr) => {
let b_status = $w.write_literal($byte);
Expand Down Expand Up @@ -450,16 +449,19 @@ fn process_chunk_lazy(
state.current_distance = 0;
state.add = false;

// As this will be a 3-length match at the end of the input data, there can't be any
// overlap.
debug_assert!((position + prev_length as usize) >= end - 1);
// Needed to note overlap as we can end up with the last window containing the rest
// of the match.
overlap = (position + prev_length as usize).saturating_sub(end).saturating_sub(1);

// TODO: Not sure if we need to signal that the buffer is full here.
// It's only needed in the case of syncing.
if let BufferStatus::Full = b_status {
// TODO: These bytes should be hashed when doing a sync flush.
// This can't be done here as the new input data does not exist yet.
return (0, buffer_full(end));
return (overlap, buffer_full(end));
} else {
return (0, ProcessStatus::Ok);
return (overlap, ProcessStatus::Ok);
}
};

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 06efadd

Please sign in to comment.