{"id":17084413,"url":"https://github.com/niklasf/rust-huffman-compress","last_synced_at":"2025-04-12T20:33:13.304Z","repository":{"id":52411982,"uuid":"119309396","full_name":"niklasf/rust-huffman-compress","owner":"niklasf","description":"A Rust library for Huffman compression given a propability distribution over arbitrary symbols","archived":false,"fork":false,"pushed_at":"2023-12-22T22:18:43.000Z","size":50,"stargazers_count":24,"open_issues_count":7,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T18:58:03.882Z","etag":null,"topics":["compression","huffman-coding","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/huffman-compress","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niklasf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","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},"funding":{"github":"niklasf"}},"created_at":"2018-01-28T23:57:20.000Z","updated_at":"2024-02-11T05:07:35.000Z","dependencies_parsed_at":"2023-12-22T23:22:38.677Z","dependency_job_id":null,"html_url":"https://github.com/niklasf/rust-huffman-compress","commit_stats":{"total_commits":91,"total_committers":2,"mean_commits":45.5,"dds":0.01098901098901095,"last_synced_commit":"1ec11d10d5fe3d88b1b42bc72b033a5ae12cb723"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-huffman-compress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-huffman-compress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-huffman-compress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Frust-huffman-compress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklasf","download_url":"https://codeload.github.com/niklasf/rust-huffman-compress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223546010,"owners_count":17163002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["compression","huffman-coding","rust"],"created_at":"2024-10-14T13:07:04.571Z","updated_at":"2024-11-07T16:03:29.551Z","avatar_url":"https://github.com/niklasf.png","language":"Rust","funding_links":["https://github.com/sponsors/niklasf"],"categories":[],"sub_categories":[],"readme":"huffman-compress\n================\n\n[Huffman compression](https://en.wikipedia.org/wiki/Huffman_coding)\ngiven a probability distribution over arbitrary symbols.\n\n[![Build Status](https://travis-ci.org/niklasf/rust-huffman-compress.svg?branch=master)](https://travis-ci.org/niklasf/rust-huffman-compress)\n[![crates.io](https://img.shields.io/crates/v/huffman-compress.svg)](https://crates.io/crates/huffman-compress)\n[![docs.rs](https://docs.rs/huffman-compress/badge.svg)](https://docs.rs/huffman-compress)\n[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](#Alternatives)\n\nAlternatives\n------------\n\nThis project has limited real-world utility. It may be useful to experiment\nwith or learn about Huffman coding\n(for example, when working on\n[bespoke chess game compression for lichess.org](https://github.com/lichess-org/compression)),\nbut there are better entropy coders (both in terms of compression ratio\nand performance) and better implementations.\n\nSee [`constriction`](https://crates.io/crates/constriction) for composable\nentropy coders, models and streams.\n\nSee [`arcode`](https://crates.io/crates/arcode) for a standalone implementation\nof arithmetic coding.\n\nExamples\n--------\n\n```rust\nuse std::iter::FromIterator;\nuse std::collections::HashMap;\nuse bit_vec::BitVec;\nuse huffman_compress::{CodeBuilder, Book, Tree};\n\nlet mut weights = HashMap::new();\nweights.insert(\"CG\", 293);\nweights.insert(\"AG\", 34);\nweights.insert(\"AT\", 4);\nweights.insert(\"CT\", 4);\nweights.insert(\"TG\", 1);\n\n// Construct a Huffman code based on the weights (e.g. counts or relative\n// frequencies).\nlet (book, tree) = CodeBuilder::from_iter(weights).finish();\n\n// More frequent symbols will be encoded with fewer bits.\nassert!(book.get(\"CG\").map_or(0, |cg| cg.len()) \u003c\n        book.get(\"AG\").map_or(0, |ag| ag.len()));\n\n// Encode some symbols using the book.\nlet mut buffer = BitVec::new();\nlet example = vec![\"AT\", \"CG\", \"AT\", \"TG\", \"AG\", \"CT\", \"CT\", \"AG\", \"CG\"];\nfor symbol in \u0026example {\n    book.encode(\u0026mut buffer, symbol);\n}\n\n// Decode the symbols using the tree.\nlet decoded: Vec\u003c\u0026str\u003e = tree.decoder(\u0026buffer).collect();\nassert_eq!(decoded, example);\n```\n\nDocumentation\n-------------\n\n[Read the documentation](https://docs.rs/huffman-compress)\n\nChangelog\n---------\n\n* 0.6.1\n  - Fix deprecation warning and remove `#[deny(warnings)]` (a future\n    compatibility hazard in libraries).\n* 0.6.0\n  - Update to `bit-vec` 0.6.\n* 0.5.0\n  - Update to `bit-vec` 0.5.\n* 0.4.0\n  - Renamed `Tree::decoder()` to `Tree::unbounded_decoder()` to avoid\n    surprises. A new `Tree::decoder()` takes the maximum number of symbols to\n    decode.\n  - No longer reexporting `Saturating` from num-traits.\n* 0.3.2\n  - Preallocate arena space for Huffman tree.\n* 0.3.1\n  - Update num-traits to 0.2 (semver compatible).\n* 0.3.0\n  - Introduce `CodeBuilder`.\n  - Changes tie breaking order.\n* 0.2.0\n  - Allow initialization from iterators without creating a `HashMap`. Thanks\n    @mernen.\n  - Require `K: Ord` instead of `K: Hash + Eq` for symbols and switch `Book`\n    internals from `HashMap` to `BTreeMap`.\n  - Specify stability guarantees.\n* 0.1.1\n  - Expose more methods on `Book`.\n* 0.1.0\n  - Initial release.\n\nLicense\n-------\n\nhuffman-compress is dual licensed under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)\nand [MIT](http://opensource.org/licenses/MIT) license, at your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Frust-huffman-compress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasf%2Frust-huffman-compress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Frust-huffman-compress/lists"}