Huffman encoding with optimized adjoin-set