This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const M = 12; // Probability scale for rANS state. Symbol frequencies in this log range. Usually 8-12. | |
const L = 23; // Renormalization factor to control dumping rANS state to bitstream. From rans_byte.h. | |
const m_min = 8 - 2 - (std.math.divCeil(u32, M, 4) catch unreachable); // Small-size-opt limit when compressing frequencies. | |
const m_max = [_]u16{m_min, m_min+16, m_min+16+256, m_min+16+256+4096, 1<<M}; // Size ranges for frequencies after small size limit. | |
fn compress(dst: anytype, src: []const u8) !void { | |
// Histogram for the frequency of each byte in input. | |
var hist = [_]u32{0} ** 256; | |
for (src) |byte| hist[byte] += 1; |