Add Huffman Encoding implementation#981
Merged
siriak merged 3 commits intoTheAlgorithms:masterfrom Dec 30, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #981 +/- ##
==========================================
- Coverage 95.77% 95.73% -0.04%
==========================================
Files 351 352 +1
Lines 22934 23166 +232
==========================================
+ Hits 21964 22178 +214
- Misses 970 988 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@siriak, this is ready to be merged. |
siriak
approved these changes
Dec 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a complete implementation of Huffman encoding to the compression module. Huffman coding is a widely-used lossless data compression algorithm that assigns variable-length codes to characters based on their frequency of occurrence.
Implementation Details
src/compression/huffman_encoding.rs(~555 lines)rustcFeatures
✅ Huffman encoding and decoding functions
✅ File processing with detailed output display
✅ Unicode support (handles all UTF-8 text)
✅ Command-line tool functionality (via
main()function)✅ Comprehensive error handling and edge cases
✅ Zero unsafe code
Algorithm Complexity
Public API
The module exports two main functions via
pub use:Testing
All tests pass with zero warnings:
Unit Tests (12/12 passing)
Documentation Tests (3/3 passing)
All doc examples compile and run correctly.
Code Quality
cargo clippy)cargo fmt)Test Coverage
Files Changed
src/compression/huffman_encoding.rs- New implementation filesrc/compression/mod.rs- Added module declaration and public exportsUsage Example
Bonus: Standalone CLI Tool
The file can also be compiled as a standalone binary:
This displays character codes, compression statistics, and verification - useful for educational purposes.
Design Decisions
Checklist
References