Skip to main content

Module abac

Module abac 

Source
Expand description

Adaptive binary arithmetic coding — integer only, bit-exact everywhere.

A carry-propagating 32-bit range coder (the LZMA construction) driven by 16-bit probabilities. Everything from a probability to an output byte is integer arithmetic, so any backend that feeds the same probabilities produces and consumes the same bytes. Probabilities come either from BitModel (two-rate adaptive counter) or straight from a model (e.g. the fixed-point network in crate::learned) via Encoder::encode_p.

Structs§

BitModel
Two-rate adaptive bit model (fast + slow exponential counters, averaged).
Decoder
Range decoder over a byte slice (reads past the end as zeros).
Encoder
Range encoder.
UintModel
Adaptive Elias-gamma style coder for unbounded non-negative integers: unary bucket k = ⌊log₂(v+1)⌋ with one model per bucket position, then the k mantissa bits (top MODELED with models, the rest raw).

Constants§

ONE
Probability scale: p1 ∈ [P_MIN, ONE − P_MIN] means P(bit = 1) = p1 / ONE.
P_MIN
Smallest probability either symbol may get.

Functions§

clamp_p
Clamp a probability of a one into the codable range.
cost_bits
Ideal code length in bits of coding bit at P(1) = p1 / 2^16.