Repository navigation
Add the LZHUF compressor - #16
Merged
Merged
Conversation
Ports the encode side of the classic LZHUF.C the client embeds (static analysis named its copy EncodeLZHUFBlock 0x4ea760, with LZHUFPutCode/LZHUFDeleteNode/LZHUFUpdate as the reference's Putcode/DeleteNode/update, used by its XFS write-back path): greedy LZSS matching over the 4096-byte ring via the per-first-byte binary search tree, each literal or (length, position) pair adaptive-Huffman coded. encodeChar lives on the same HuffmanTree the decoder evolves, and the encoder position tables are derived from the decoder's dCode/dLen instead of transcribed, so the two sides cannot drift apart. Tests round-trip the sample fixtures, real characterdata.dat, and degenerate/reconst-forcing/multi-window inputs — and pin the encoder byte-for-byte against the .lzh fixtures produced by the original reference LZHUF.C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
LZHUF.compress— the encode side of the classic public-domainLZHUF.Cthe client embeds. Static analysis of the original binary recently named its copy of the encoder (EncodeLZHUFBlock0x4ea760, withLZHUFPutCode/LZHUFDeleteNode/LZHUFUpdatematching the reference'sPutcode/DeleteNode/update, used by its XFS write-back path), confirming the client ships the reference compressor, not just the decoder.InsertNode/DeleteNodeported exactly, including full-match node replacement and lowest-position tie-breaking), each literal or (length, position) pair adaptive-Huffman coded.encodeCharlives on the sameHuffmanTreethe decoder evolves, and the encoder position tables are derived from the decoder'sdCode/dLenrather than transcribed — the two sides are inverse by construction and cannot drift apart.BitWritermirrorsBitReader(Putcodesemantics, including the two-byte spill path).Tests
Six new tests in
LZHUFCompressTests:.lzhfixtures (they were produced by the originalLZHUF.C; a faithful port must reproduce them exactly, minus the CLI's 4-byte size header) — the strongest validation possible.characterdata.datpayload, degenerate inputs (empty / single byte / all-identical), >32K-symbol data forcing the adaptive-Huffmanreconstrebuild on both sides, and multi-window repetitive data exercising both position-code bands.Test plan
swift test— 566 tests passing