2 releases
0.1.1 | Nov 13, 2024 |
---|---|
0.1.0 | Nov 13, 2024 |
#320 in Compression
46 downloads per month
32KB
650 lines
hfmn
hfmn is a flexible Huffman coding implementation
Usage
Add this to your Cargo.toml:
[dependencies]
hfmn = "0.15"
Then:
use hfmn::Coding;
let data = "An arbitrary test string";
let coding = Coding::from_data(data).unwrap();
let encoded = coding.encode(data);
println!("{:?}", encoded);
lib.rs
:
hfmn is a library for huffman encoding and decoding of arbitrary symbols. It
supports code lengths up to std::mem::size_of::<usize>() * 8
bits.
Nomenclature
- Symbol refers to your data, which can be of an arbitrary type
- Code refers to the prefix-free huffman code
Examples
use hfmn::CodeBook;
let data_to_encode = "lorem ipsum dolor sit amet";
let codebook = CodeBook::from_data(&data_to_encode).unwrap();
let encoded_data = codebook.encode_data(&data_to_encode).unwrap();
let more_encoded_data = codebook.encode_data(&"optimum allied restrooms");
Dependencies
~1–1.8MB
~37K SLoC