{"id":15354552,"url":"https://github.com/kennethnym/huffmantextcompression","last_synced_at":"2026-06-19T16:01:15.578Z","repository":{"id":110250465,"uuid":"345636938","full_name":"kennethnym/HuffmanTextCompression","owner":"kennethnym","description":"Java implementation of the Huffman coding compression.","archived":false,"fork":false,"pushed_at":"2021-03-17T17:26:35.000Z","size":147,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-02T00:02:47.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kennethnym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-08T11:44:53.000Z","updated_at":"2024-06-20T18:08:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"543994f6-f0c6-4fea-9332-5f1f4c78a9b9","html_url":"https://github.com/kennethnym/HuffmanTextCompression","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":"0.15384615384615385","last_synced_commit":"5fecdcc2e3309f61ad721dea37c104d6604f3ddf"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kennethnym/HuffmanTextCompression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethnym%2FHuffmanTextCompression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethnym%2FHuffmanTextCompression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethnym%2FHuffmanTextCompression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethnym%2FHuffmanTextCompression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kennethnym","download_url":"https://codeload.github.com/kennethnym/HuffmanTextCompression/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethnym%2FHuffmanTextCompression/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34538480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:19:44.895Z","updated_at":"2026-06-19T16:01:15.536Z","avatar_url":"https://github.com/kennethnym.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Huffman compression\n\nThis project is a Java implementation of the Huffman coding algorithm.\n\n## Getting started\n\nFirst, clone this repository.\n\nTo run this program, simply do:\n\n```\n./gradlew run\n```\n\nor, on Windows:\n\n```\n.\\gradlew run\n```\n\nThe program has been tested on Windows 10 and macOS Big Sur.\n\n## Implementation\n\nHuffman coding algorithms compresses texts by assigning fewer bits to store characters that appear more often in the\nsource text. It generates a binary tree where more frequent characters are higher up in the tree.\n\nIn this implementation, instead of counting the frequencies of characters, it counts the frequencies of bytes in a given\nbyte array. Decompression works by traversing the resulting tree and reconstructing the byte array back.\n\nThe tree that is generated is stored at the start of the compressed file before the actual compressed content, by\nserializing the tree into a compact format that takes up as little extra space as possible.\n\n### Serialization format\n\nThe serialized tree is represented in bytes. In order to illustrate the format, however, more readable characters are\nused to represent the special bytes in the serialized data.\n\nConsider a simple binary tree with one root node and two child nodes under the root. The number `1` is stored in the\nleft node, and the number `2` is stored in the right node. It may be serialized into the following by the algorithm:\n\n```\nRl1^r2\n```\n\n`R` stands for the root of the tree.\n`l` and `r` (called the *direction code*) represents the left and right node of the previous node respectively. Anything\nbetween a direction code and the next direction code represents the content of the node. If the node is empty, then a\ndirection code may immediately be followed by another code.\n\nConsider the following serialized tree:\n\n```\nRll2^r2^^r1\n```\n\nit can be visualized as follows:\n\n![visualization of serialization format](./assets/images/serialization_visualized.png)\n\nIn order to obtain the serialized format, the following procedures may be followed:\n\n- Traverse the tree in a pre-order manner, marking down the direction of the node along the way.\n- For every node that has content in it, also note down its content before visiting the next node.\n- If the next node is at the same or at an upper level, add `^` equal to the difference between the current level and the next level plus 1.\n  For example, if the next node is 2 levels up, add 3 `^` as such: `^^^`.\n  If the difference is 0, add 1 `^`.\n- If the next node is below the current node, no special notation is required.\n\nStoring the serialized tree in string format induces additional overhead\n(having to decode the underlying bytes into readable characters). Instead, the special notations like direction codes\nare represented by negative numbers. The notations and the node content are then stored as `short`s. The following table\nshows how the special notations are mapped to negative numbers:\n\n| Notation | Corresponding number |\n| -------- | -------------------- |\n| `R`      | `-5`                 |\n| `r`      | `-4`                 |\n| `l`      | `-3`                 |\n| `^`      | `-2`                 |\n\n`-1` is not used because it is reserved to indicate EOF in Java.\n\n## Books used\n\nThe following books are used to test the effectiveness of the algorithm.\nThey are available for free at [this website](https://www.gutenberg.org/).\n\n- The Origin of Thought and Speech by M. Moncalm\n- Jane Seton by James Grant\n- A Revolução Portugueza: O 31 de Janeiro (Porto 1891) by Francisco Jorge de Abreu\n- The Penitente Moradas of Abiquiú by Richard E. Ahlborn\n- Germana by Edmond About\n- La nariz de un notario by Edmond About\n\n## Corpus dataset used\n\nThe following corpus datasets are used to test the effectiveness of the algorithm.\nThey are availble for free at [this website](http://pizzachili.dcc.uchile.cl/repcorpus.html).\n\n- fib41\n- dblp.xml.00001.1\n- para\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethnym%2Fhuffmantextcompression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkennethnym%2Fhuffmantextcompression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethnym%2Fhuffmantextcompression/lists"}