implement huffman encoder