| Crates.io | huffman-encoding |
| lib.rs | huffman-encoding |
| version | 0.1.2 |
| created_at | 2021-06-09 15:06:54.23137+00 |
| updated_at | 2021-06-09 15:27:08.1151+00 |
| description | Huffman encoding of arbitrary data |
| homepage | |
| repository | |
| max_upload_size | |
| id | 408202 |
| size | 8,522 |
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);