From c0b48dedf98adb7a518089638d4cc28fe1d2c4ac Mon Sep 17 00:00:00 2001 From: Andrew Duffy Date: Wed, 21 Aug 2024 10:50:46 -0400 Subject: [PATCH] add single bytes as candidates --- src/builder.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index cc58190..84243df 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -252,6 +252,14 @@ impl Compressor { counter.record_count1(code); counter.record_count2(prev_code, code); + // Record the first byte of `code` as its own symbol so that it is a candidate for merging + // with `prev_code`. This allows us to grow the symbol table by one byte rather than + // concatenating a full symbol. + if code >= 256 { + let first_byte = self.symbols[code as usize].first_byte(); + counter.record_count2(prev_code, first_byte as u16); + } + prev_code = code; } }