#endif
#include "wimlib/assert.h"
+#include "wimlib/endianness.h"
#include "wimlib/compiler.h"
#include "wimlib/compress.h"
#include "wimlib/util.h"
ostream->bit_output = data;
ostream->next_bit_output = data + 2;
ostream->output = data + 4;
- ostream->bytes_remaining = num_bytes;
+ ostream->bytes_remaining = num_bytes - 4;
ostream->overrun = false;
}
typedef struct {
- freq_t freq;
+ input_idx_t freq;
u16 sym;
union {
u16 path_len;
* @num_syms: The number of symbols in the alphabet.
*
* @max_codeword_len: The maximum allowed length of a codeword in the code.
- * Note that if the code being created runs up against
- * this restriction, the code ultimately created will be
- * suboptimal, although there are some advantages for
- * limiting the length of the codewords.
+ * Note that if the code being created runs up against
+ * this restriction, the code ultimately created will be
+ * suboptimal, although there are some advantages for
+ * limiting the length of the codewords.
*
* @freq_tab: An array of length @num_syms that contains the frequencies
- * of each symbol in the uncompressed data.
+ * of each symbol in the uncompressed data.
*
* @lens: An array of length @num_syms into which the lengths of the
- * codewords for each symbol will be written.
+ * codewords for each symbol will be written.
*
* @codewords: An array of @num_syms short integers into which the
- * codewords for each symbol will be written. The first
- * lens[i] bits of codewords[i] will contain the codeword
- * for symbol i.
+ * codewords for each symbol will be written. The first
+ * lens[i] bits of codewords[i] will contain the codeword
+ * for symbol i.
*/
void
make_canonical_huffman_code(unsigned num_syms,
unsigned max_codeword_len,
- const freq_t freq_tab[restrict],
+ const input_idx_t freq_tab[restrict],
u8 lens[restrict],
u16 codewords[restrict])
{
* log_2(num_used_symbols).
* */
for (unsigned i = 0; i < num_used_symbols; i++)
- if (leaves[i].freq > 1)
- leaves[i].freq >>= 1;
+ leaves[i].freq = (leaves[i].freq + 1) >> 1;
+
goto try_building_tree_again;
}
next_inode++;