Skip to content

Add Huffman Coding compression (1951)#4

Draft
google-labs-jules[bot] wants to merge 2 commits into
mainfrom
add-huffman-compression-10554524431435534885
Draft

Add Huffman Coding compression (1951)#4
google-labs-jules[bot] wants to merge 2 commits into
mainfrom
add-huffman-compression-10554524431435534885

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This change adds Huffman Coding compression to the editor, extending its capabilities with a classic, frequency-based algorithm. The implementation is fully integrated into the existing compression framework and UI, and the project's documentation has been updated accordingly.

Fixes #1


PR created automatically by Jules for task 10554524431435534885 started by @artiphishle

Implements Huffman coding as a new compression algorithm in the text editor.

- Adds `HuffmanCompression.java` with the full implementation of the Huffman algorithm, including frequency table generation, tree building, and bitstream packing.
- Handles the edge case of input with a single unique character.
- Integrates the new compression method into the `TextEditor` UI with "Compress (Huffman)" and "Decompress (Huffman)" menu items.
- Updates the `README.md` to include a description of Huffman coding and its historical context.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

This commit fixes a critical bug in the Huffman compression algorithm that caused decompression to fail.

The root cause of the issue was non-deterministic Huffman tree generation. When characters had the same frequency, the `PriorityQueue`'s ordering was not guaranteed, leading to different tree structures between compression and decompression. A code generated with one tree could be invalid for another, causing a `NullPointerException` during decoding.

To resolve this, the `PriorityQueue` comparator in `buildHuffmanTree` has been updated. It now uses the character's byte value as a secondary sorting key to break ties when frequencies are equal. This ensures that the Huffman tree is constructed identically every time, making the compression and decompression processes consistent and reliable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Huffmann Coding compression (1951)

0 participants