Module dsi_bitstream::codes

source ·
Expand description

Traits for reading and writing instantaneous codes.

This modules contains code for reading and writing instantaneous codes. Codewords are uniformely indexed from 0 for codes. For example, the first few words of unary, γ, and δ codes are:

Argunaryγδ
0111
1010100100
20010110101
300010010001100
4000010010101101
50000010011001110
600000010011101111
700000001000100000100000

Each code is implemented as a pair of traits for reading and writing (e.g., GammaReadParam and GammaWriteParam). The traits for reading depend on BitRead, whereas the traits for writing depend on BitWrite.

The traits ending with Param make it possible to specify parameters—for example, whether to use decoding tables. Usually, one whould instead pull in scope non-parametric traits such as GammaRead and GammaWrite, for which defaults are provided using the mechanism described in the params module.

Note that if you are using decoding tables, you must ensure that the peek_bits method of your BitRead implementation returns a sufficient number of bits: if it does not, an assertion will be triggered in test mode, but behavior will be unpredictable otherwise. This is unfortunately difficult to check statically. To stay on the safe side, we recommend to use a read word of at least 16 bits.

Re-exports§

Modules§