{"id":49883503,"url":"https://github.com/rushil-ambati/huffpy","last_synced_at":"2026-05-15T16:35:21.949Z","repository":{"id":185442523,"uuid":"260295143","full_name":"rushil-ambati/huffpy","owner":"rushil-ambati","description":"Huffman encoder and decoder built in python","archived":false,"fork":false,"pushed_at":"2021-04-03T18:01:40.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-08-01T23:29:57.276Z","etag":null,"topics":["heap","huffman-encoder","traversal","tree"],"latest_commit_sha":null,"homepage":"","language":"Python","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/rushil-ambati.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}},"created_at":"2020-04-30T19:02:23.000Z","updated_at":"2023-08-01T23:29:59.137Z","dependencies_parsed_at":null,"dependency_job_id":"7117c821-28bc-41cd-9720-c6c9e75365a6","html_url":"https://github.com/rushil-ambati/huffpy","commit_stats":null,"previous_names":["rushil-ambati/huffpy"],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/rushil-ambati/huffpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rushil-ambati%2Fhuffpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rushil-ambati%2Fhuffpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rushil-ambati%2Fhuffpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rushil-ambati%2Fhuffpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rushil-ambati","download_url":"https://codeload.github.com/rushil-ambati/huffpy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rushil-ambati%2Fhuffpy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33072619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["heap","huffman-encoder","traversal","tree"],"created_at":"2026-05-15T16:35:20.873Z","updated_at":"2026-05-15T16:35:21.938Z","avatar_url":"https://github.com/rushil-ambati.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# huffpy\n**A Huffman encoder built in python**\n\nThis Huffman encoder was built using only python’s core modules. It does not use heaps/stacks such as those present in the `heapq` library and is therefore very inefficient in comparison. It also comes with a decoder that interfaces with a text file output by the encoder.\n\n## Instructions\nTo run the encoder script:\n- Paste the input into a textfile in the same directory as the script named `input.txt`.\n- Run the script as a regular python script - opening a terminal in the directory of installation and entering `python encoder.py`.\nThis will show the methodology of conversion into the console and write the output letter dictionary and encoded binary string to a textfile called `encoded_output.txt`.\n\nTo run the decoder script:\n- Run the script as a regular python script - opening a terminal in the directory of installation and entering `python decoder.py`.\nThis will take the encoded information in the encoded_output textfile and decode it, outputting the plaintext to the console.\n\n## Verbose output\nBoth scripts have a `DIAG` variable that, when set to true, will give verbose diagnostic output.\nVerbose output is enabled by default - if you wish to disable it, change the variable on line 2 of each script from\n`DIAG = True`\nto\n`DIAG = False`\n\n## Methodology\nThis script is an implementation of the Huffman encoding technique.\nIt works by:\n- Taking input from a file\n\n- Counting the number of occurences of each unique character in the input text\n- Ordering them ascendantly\n\n- Constructing a binary tree by:\n  - Pairing the first two elements of the ascendantly ordered list into leaves of a node\n  - Adding this new node into the list\n  - Ordering the list again\n  - Running the above steps continuously until the list reaches length 1 (the root).\n\n- Encoding text by iterating through each character present, and for each one:\n  - Searching the tree for that charater's node (linearly - O(n))\n  - Finding the parent node to that character node (also linearly - O(n))\n  - Labelling the traversal up one layer as either left or right\n  - Traversing upwards in this fashion until the root is reached\n  - Producing a string for the definition of each character\n\n- Using the dictionary and the text, encoding it with the new binary tree derived definitions for each character.\n  - There are spaces between each character to split them - this is an issue with variable length encoding compared to fixed length as splits between character bit signals are not constant.\n\n- Outputting the encoded text and dictionary, and displaying (if diagnostics are enabled) the theoretical efficiency improvement over 8-bit ASCII text encoding.\n\nIn theory, the most frequently present characters will have the shortest bit definitions.\n\n## TODO\n- Implement a more efficient tree traversal/search algorithm. (DFS? BFS?)\n- Change the current 'diagnostics' implementation:\n  - Disable diagnostic output by default\n  - Using the `argparse` module, use a flag on run to enable/disable diagnostics\n- Re-implement the encoder using heaps/stacks and calculate big O, and delta between both implementations\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frushil-ambati%2Fhuffpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frushil-ambati%2Fhuffpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frushil-ambati%2Fhuffpy/lists"}