Implements huffman encoding of strings