minimum_redundancy is the Rust library by Piotr Beling to encode and decode data
with binary or non-binary Huffman coding.
The library can construct and concisely represent optimal prefix (minimum-redundancy) coding whose codewords are of length divisible by a given number of bits (1-bit, 2-bits, ...).
The library uses modified Huffman algorithm, with ideas from papers:
- A. Brodnik, S. Carlsson, Sub-linear decoding of Huffman Codes Almost In-Place, 1998
- A. Moffat, J. Katajainen, In-Place Calculation of Minimum-Redundancy Codes. In: Akl S.G., Dehne F., Sack JR., Santoro N. (eds) Algorithms and Data Structures. WADS 1995. Lecture Notes in Computer Science, vol 955. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-60220-8_79
Example
use ;
use hashmap;
// Construct coding with 1 bit per fragment for values 'a', 'b', 'c',
// whose frequencies of occurrence are 100, 50, 10 times, respectively.
let huffman = from_frequencies_bits_per_fragment;
// We expected the following Huffman tree:
// / \
// /\ a
// bc
// and the following code assignment: a -> 1, b -> 00, c -> 01
assert_eq!;
let mut decoder_for_a = huffman.decoder;
assert_eq!;
let mut decoder_for_b = huffman.decoder;
assert_eq!;
assert_eq!;
let mut decoder_for_c = huffman.decoder;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;