First implementation for huffman encoding.