From b10f1eaed6c0a1668e2ca8d11ac90136980ef257 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 1dda9c9..660531f 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -207,6 +207,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; } }