huffman-compress
Huffman compression given a probability distribution over arbitrary symbols.
Examples
use FromIterator;
use HashMap;
use BitVec;
use ;
let mut weights = new;
weights.insert;
weights.insert;
weights.insert;
weights.insert;
weights.insert;
// Construct a Huffman code based on the weights (e.g. counts or relative
// frequencies).
let = from_iter.finish;
// More frequent symbols will be encoded with fewer bits.
assert!;
// Encode some symbols using the book.
let mut buffer = new;
let example = vec!;
for symbol in &example
// Decode the symbols using the tree.
let decoded: = tree.decoder.collect;
assert_eq!;
Documentation
Changelog
- 0.3.1
- Update num-traits to 0.2 (semver compatible).
- 0.3.0
- Introduce
CodeBuilder
. - Changes tie breaking order.
- Introduce
- 0.2.0
- Allow initialization from iterators without creating a
HashMap
. Thanks @mernen. - Require
K: Ord
instead ofK: Hash + Eq
for symbols and switchBook
internals fromHashMap
toBTreeMap
. - Specify stability guarantees.
- Allow initialization from iterators without creating a
- 0.1.1
- Expose more methods on
Book
.
- Expose more methods on
- 0.1.0
- Initial release.
License
huffman-compress is dual licensed under the Apache 2.0 and MIT license, at your option.