Expand description
An adaptive Huffman encoder, for use in compression schemes.
To encode data, instantiate a Codec
object, and repeatedly call
Codec::write_and_update
. To decode data, instantiate a Codec
object,
and repeatedly call Codec::read_and_update
.
State is shared between the encoder and decoder implicitly; that is, it is constructed from the sequence of encoded or decoded symbols, rather than being communicated in the data. Thus, exactly the same data must be decoded on the decode side as was encoded on the encode side, or the decoder will go off the rails and produce nonsense. Furthermore, each side must be constructed with the same parameters, and the same major version of this library must be used.
The encoder does not emit any special symbol for EOF. Thus, either the application must designate its own EOF symbol (emitting it on the encoder, and stopping decoding when it is read), or it must somehow communicate the length of the input file out of band and only read that many symbols.
Structs§
- Codec
- The core struct used to encode and decode adaptive Huffman data. Exactly the same series of symbols must be decoded by the decoder as were encoded by the encoder, and the tree must be instantiated with the same parameters on both sides; because the state is updated in a deterministic way, this ensures that the decoder implicitly knows the encoder’s state at any point, without having to physically communicate an encoding tree or other information.