huffman encode implementation