diff --git a/src/output.zig b/src/output.zig index c1dac8e..35cb73a 100644 --- a/src/output.zig +++ b/src/output.zig @@ -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; }