Skip to content

Commit

Permalink
Fix build.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed May 21, 2024
1 parent 885d17c commit fb948ee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests/implode_hamlet_256.bin binary
tests/reduce_hamlet_2048.bin binary
tests/reduce_zero_reduced.bin binary
4 changes: 2 additions & 2 deletions src/legacy/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ fn read_next_byte<T: std::io::Read, E: Endianness>(
fsets: &mut FollowerSetArray,
) -> io::Result<u8> {
if fsets[prev_byte as usize].size == 0 // No followers
|| is.read::<u8>(1)? == 1 // Indicates next symbol is a literal byte
|| is.read::<u8>(1)? == 1
// Indicates next symbol is a literal byte
{

return Ok(is.read::<u8>(8)?);
}

Expand Down
37 changes: 24 additions & 13 deletions src/legacy/shrink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,30 @@ fn read_code<T: std::io::Read, E: Endianness>(
}

// Handle control codes.
let control_code = if let Ok(c) = is.read::<u16>(*code_size as u32) {
c
} else {
return Ok(None);
};
if control_code == INC_CODE_SIZE && *code_size < MAX_CODE_SIZE {
(*code_size) += 1;
return read_code(is, code_size, codetab, queue);
}
if control_code == PARTIAL_CLEAR {
unshrink_partial_clear(codetab, queue);
if let Ok(control_code) = is.read::<u16>(*code_size as u32) {
match control_code {
INC_CODE_SIZE => {
if *code_size >= MAX_CODE_SIZE {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"tried to increase code size when already at maximum",
));
}
*code_size += 1;
}
PARTIAL_CLEAR => {
unshrink_partial_clear(codetab, queue);
}
_ => {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("Invalid control code {}", control_code),
));
}
}
return read_code(is, code_size, codetab, queue);
}
return Ok(None);
Ok(None)
}

/// Output the string represented by a code into dst at dst_pos. Returns
Expand Down Expand Up @@ -291,7 +301,8 @@ fn hwunshrink(src: &[u8], uncompressed_size: usize, dst: &mut VecDeque<u8>) -> i
&mut codetab,
&mut queue,
&mut first_byte,
&mut len)?;
&mut len,
)?;

// Add a new code to the string table if there's room.
// The string is the previous code's string extended with
Expand Down

0 comments on commit fb948ee

Please sign in to comment.