Get the latest tech news
Building a data compression utility in Haskell using Huffman codes
In this post we will implement a data compression program in about 150 lines of Haskell. It will use Huffman coding and handle arbitrary binary files using constant memory for encoding and decoding.
Notice how go function, upon reaching a Leaf, returns a list where the head is known and the tail is a recursive call. Because we won’t use the[Bit] or ByteString in other parts of the program, the garbage collector will be able to free the memory we just allocated for that portion of input that we decoded. Canonical Huffman codes- Instead of navigating the tree for decoding in O(log n), we can use the code to index directly into a vector in O(1).
Or read this on Hacker News