#huffman #huffman-coding #data #encode #decode

huffman-encoding

Huffman encoding of arbitrary data

3 releases

0.1.2 Jun 9, 2021
0.1.1 Jun 9, 2021
0.1.0 Jun 9, 2021

#681 in Compression

MIT/Apache

9KB
202 lines

huffman-encoding

crates.io

Usage

Add this to your Cargo.toml:

[dependencies]
huffman-encoding = "0.1"
// weights are represented as value -> frequency pairs
let weights = vec![
  ("hello".to_string(), 2),
  ("hey".to_string(), 3),
  ("howdy".to_string(), 1),
];
let huffman = huffman_encoding::Huffman::new(weights).unwrap();
let data = vec!["howdy".into(), "howdy".into(), "hey".into(), "hello".into()];
// encode into a bit_vec::BitVec
let encoded = huffman.encode(&data).unwrap();
// decode back into a Vec<String>
let decoded = huffman.decode_owned(&encoded);

Dependencies

~0.4–0.9MB
~20K SLoC