Add LZW compression module - #2767
Open
dakshp26 wants to merge 3 commits into
Open
Conversation
Implement Lempel-Ziv-Welch (LZW) encoding and decoding under algorithms/compression, following the style of existing modules (huffman_coding, rle_compression, elias). - lzw_encode(data) returns a tuple of (codes, initial_dictionary), making the API self-contained since the decoder needs the same character-to-code mapping. - lzw_decode(codes, initial_dictionary) reconstructs the dictionary on the fly and recovers the original string. - Handles edge cases including empty input. - Adds unit tests covering encoding, decoding, round-trip, and empty input. - Exports lzw_encode and lzw_decode from compression/__init__.py.
keon
approved these changes
Jul 29, 2026
Owner
|
thanks for the contribution! |
Author
|
I have fixed the lint error that ruff check found (dictionary line too long). Please let me know if I should make any other modifications. Thanks! |
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.
Summary
Adds a new LZW (Lempel-Ziv-Welch) compression implementation to the algorithms/compression package.
Changes
Conventions
Follows existing project conventions:
Testing
All 4 LZW tests pass: