bit table gen algo fix

This commit is contained in:
Muaz Ahmad 2023-12-12 14:25:39 +05:00
parent 9648f06186
commit f97456aab8

View file

@ -209,7 +209,6 @@ inline fn gen_codes(huff: *Huffman, huffman_meta: HuffmanMeta) !void {
si += 1;
}
}
for (0..total_k) |x| {
try huff.put(huffman_meta.huffval[x], HuffCode{
.n_bits = huffsize[x],
@ -244,17 +243,15 @@ inline fn gen_huffman(freqs: []u32) HuffmanMeta {
bits[codesizes[i]] += 1;
}
}
var i: usize = 32;
while (i > 16) {
if (bits[i] > 0) {
var j = i - 2;
while (bits[j] <= 0) : (j -= 1) {
bits[i] -= 2;
bits[i - 1] += 1;
bits[j + 1] += 2;
bits[j] -= 1;
}
while (bits[j] <= 0) : (j -= 1) {}
bits[i] -= 2;
bits[i - 1] += 1;
bits[j + 1] += 2;
bits[j] -= 1;
} else {
i -= 1;
}