huffman-encoding

Crates.iohuffman-encoding
lib.rshuffman-encoding
version0.1.2
sourcesrc
created_at2021-06-09 15:06:54.23137
updated_at2021-06-09 15:27:08.1151
descriptionHuffman encoding of arbitrary data
homepage
repository
max_upload_size
id408202
size8,522
Conner Bryan (cab)

documentation

README

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);
Commit count: 0

cargo fmt