This Rust library implements two essential coding techniques for data transmission:
Source Coding (Huffman Coding): A method of data compression that reduces redundancy in the source message, using variable-length codes to represent frequent symbols with shorter codes.
Channel Coding (Binary BCH Coding): A method of error correction used in communication systems. Binary BCH (Bose–Chaudhuri–Hocquenghem) codes detect and correct errors in transmitted data to ensure reliability over noisy channels.
- Huffman Encoding and Decoding for efficient data compression.
- Binary BCH Encoding and Decoding for error correction in communication channels.
- Written in Rust, ensuring performance and memory safety.
- Fully documented and tested with examples.
To use this library in your project, add it to your Cargo.toml:
[dependencies]
coding_lib = "0.1.0"Note: Replace coding_lib with the actual name once you publish it.
use coding_lib::huffman;fnmain(){let data = "hello, world!";let(encoded, tree) = huffman::encode(data);let decoded = huffman::decode(&encoded,&tree);println!("Original: {}", data);println!("Encoded: {:?}", encoded);println!("Decoded: {}", decoded);}use coding_lib::bch;fnmain(){let message = vec![1,0,1,1];// Binary messagelet encoded = bch::encode(&message);let decoded = bch::decode(&encoded).expect("Failed to decode");println!("Original: {:?}", message);println!("Encoded: {:?}", encoded);println!("Decoded: {:?}", decoded);}Check the examples directory for more use cases and detailed examples.
To run the tests, use:
cargo testThis will run the unit tests for both Huffman and BCH implementations.
Contributions are welcome! Feel free to open an issue or submit a pull request with improvements or bug fixes.
This project is licensed under the MIT License.