Collect common code from fixed and dynamic Huffman.
Factor out part that builds dynamic Huffman trees.