-static unsigned
-lzx_huffman_code_output_cost(const u8 lens[restrict],
- const freq_t freqs[restrict],
- unsigned num_syms)
-{
- unsigned cost = 0;
-
- for (unsigned i = 0; i < num_syms; i++)
- cost += (unsigned)lens[i] * (unsigned)freqs[i];
-
- return cost;
-}
-
-/* Return the number of bits required to output the lengths for the specified
- * Huffman code in compressed format (encoded with a precode). */
-static unsigned
-lzx_code_cost(const u8 lens[], const u8 prev_lens[], unsigned num_syms)
-{
- u8 output_syms[num_syms];
- freq_t precode_freqs[LZX_PRETREE_NUM_SYMBOLS];
- u8 precode_lens[LZX_PRETREE_NUM_SYMBOLS];
- u16 precode_codewords[LZX_PRETREE_NUM_SYMBOLS];
- unsigned cost = 0;
- unsigned num_additional_bits;
-
- /* Acount for the lengths of the precode itself. */
- cost += LZX_PRETREE_NUM_SYMBOLS * LZX_PRETREE_ELEMENT_SIZE;
-
- lzx_build_precode(lens, prev_lens, num_syms,
- precode_freqs, output_syms,
- precode_lens, precode_codewords,
- &num_additional_bits);
-
- /* Account for all precode symbols output. */
- cost += lzx_huffman_code_output_cost(precode_lens, precode_freqs,
- LZX_PRETREE_NUM_SYMBOLS);
-
- /* Account for additional bits. */
- cost += num_additional_bits;
-
- return cost;
-}
-