Hacker News new | ask | show | jobs
by mamaniscalco 3372 days ago
Encoding can be greatly speed up by constructing an array of the codes for each symbol (left justified) plus the code length. During encode you look up the code for the current symbol, shift it to align with the current output bit position, bitwise or it into the output stream and adjust your output position according to the code length. Similarly an array of the codes can be used to decode quickly as well using a binary search. Avoid using tree traversal when encoding and decoding to greatly increase performance.

Also, Huffman is fast becoming obsolete with the introduction of ANS.

1 comments

Thank you, this is exactly the sort of feedback I was looking for.

And that's a nice find on the ANS. I hadn't heard of that before, but will have to look into it.

I'll push a high permormance Huffman to github for reference later on today and post a link here.

For ANS info start with this link that leads to a thread by its creator:

https://encode.ru/threads/2078-List-of-Asymmetric-Numeral-Sy...