Module minimal_binary

Source
Expand description

Minimal binary codes.

A minimal binary code with upper bound u > 0 (AKA truncated binary encoding) is an optimal prefix-free code for the first u natural numbers with uniform distribution.

There are several such codes, and the one implemented here is defined as follows: let s = ⌈log₂u⌉; then, given x < u, if x < 2ˢu then x is coded as the binary representation of x in s − 1 bits; otherwise, x is coded as the binary representation of xu + 2ˢ in s bits.

See the codes module documentation for some elaboration on the difference between the big-endian and little-endian versions of the codes.

Traits§

MinimalBinaryRead
Trait for reading minimal binary codes.
MinimalBinaryWrite
Trait for writing minimal binary codes.

Functions§

len_minimal_binary
Returns the length of the minimal binary code for n with upper bound max.