Skip to main content

Module rans

Module rans 

Source
Expand description

Interleaved rANS (Asymmetric Numeral Systems) entropy coder.

Compresses byte streams to the Shannon entropy limit — optimal compression ratio at Huffman-like speed. Used as the terminal compressor for cold/S3 tier partitions where ratio matters more than decompression speed.

4-stream interleaving breaks the sequential dependency chain: the CPU processes all streams simultaneously, achieving high throughput despite the inherently sequential nature of ANS.

Wire format:

[4 bytes] uncompressed size (LE u32)
[256 × 4 bytes] frequency table (LE u32 per byte value)
[4 bytes] compressed size (LE u32)
[N bytes] interleaved rANS bitstream (4 streams)

Functions§

decode
Decompress interleaved rANS data.
encode
Compress bytes using interleaved rANS.