Module gamma

Source
Expand description

Elias γ code.

The γ code of a natural number n is the concatenation of the unary code of ⌊log₂(n + 1)⌋ and of the binary representation of n + 1 with the most significant bit removed.

The implied distribution of the γ code is ≈ 1/2x².

The USE_TABLE parameter enables or disables the use of pre-computed tables for decoding.

§References

Peter Elias, “Universal codeword sets and representations of the integers”. IEEE Transactions on Information Theory, 21(2):194−203, March 1975.

Traits§

GammaRead
Trait for reading γ codes.
GammaReadParam
Parametric trait for reading γ codes.
GammaWrite
Trait for writing γ codes.
GammaWriteParam
Parametric trait for writing γ codes.

Functions§

len_gamma
Returns the length of the γ code for n using a default value for USE_TABLE.
len_gamma_param
Returns the length of the γ code for n.