Cyan4973 / FiniteStateEntropy

New generation entropy codecs : Finite State Entropy and Huff0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why Huffman code in reverse order?

huhu0823 opened this issue · comments

commented

I'm very interested in compression.Huffman coding can be performed sequentially,I can't understand why huffman code is executed in reverse order in the code.

FSE needs to encode and decode in reverse directions.
There are multiple conventions possible, this implementation selects to write the compressed bitstream forward, and read backward.
This results in a bitstream format, which is built around the assumption of forward writing, and backward reading.

For simplicity, the Huffman implementation in this repository employs the same bitstream.
Since the compressed bitstream will be read backward, but we still want the decoded symbols to be written forward, it follows that they must be written in the compressed bitstream in reverse order.

Obviously, other conventions could have been used. And it's also possible to read + write huffman forward, which is probably easier to follow. This would "just" require another bitstream implementation.

commented

FSE needs to encode and decode in reverse directions. There are multiple conventions possible, this implementation selects to write the compressed bitstream forward, and read backward. This results in a bitstream format, which is built around the assumption of forward writing, and backward reading.

For simplicity, the Huffman implementation in this repository employs the same bitstream. Since the compressed bitstream will be read backward, but we still want the decoded symbols to be written forward, it follows that they must be written in the compressed bitstream in reverse order.

Obviously, other conventions could have been used. And it's also possible to read + write huffman forward, which is probably easier to follow. This would "just" require another bitstream implementation.

Thank you for your reply!Your answer made me suddenly understand.