implemented Huffman.encode