{"id":50574734,"url":"https://github.com/pmcgleenon/heavykeeper-rs","last_synced_at":"2026-06-04T21:00:50.785Z","repository":{"id":242189842,"uuid":"772238033","full_name":"pmcgleenon/heavykeeper-rs","owner":"pmcgleenon","description":"Heavykeeper algorithm for Top-K elephant flows","archived":false,"fork":false,"pushed_at":"2026-05-10T13:36:41.000Z","size":1396,"stargazers_count":8,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-05-10T15:29:03.516Z","etag":null,"topics":["heavykeeper","probabilistic-data-structures","rust","sketch","top-k"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/heavykeeper","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmcgleenon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-14T19:54:55.000Z","updated_at":"2026-05-10T13:36:13.000Z","dependencies_parsed_at":"2024-06-08T10:43:13.342Z","dependency_job_id":"faec5695-956f-4b27-bf5e-f4077ab7fdb7","html_url":"https://github.com/pmcgleenon/heavykeeper-rs","commit_stats":null,"previous_names":["pmcgleenon/heavykeeper-rs"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/pmcgleenon/heavykeeper-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmcgleenon%2Fheavykeeper-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmcgleenon%2Fheavykeeper-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmcgleenon%2Fheavykeeper-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmcgleenon%2Fheavykeeper-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmcgleenon","download_url":"https://codeload.github.com/pmcgleenon/heavykeeper-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmcgleenon%2Fheavykeeper-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33917202,"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-04T02:00:06.755Z","response_time":64,"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":["heavykeeper","probabilistic-data-structures","rust","sketch","top-k"],"created_at":"2026-06-04T21:00:36.462Z","updated_at":"2026-06-04T21:00:50.750Z","avatar_url":"https://github.com/pmcgleenon.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# heavykeeper-rs\n\n[![Crates.io][crates-badge]][crates-url]\n[![MIT / Apache 2.0 licensed][license-badge]][license-url]\n[![Build Status][actions-badge]][actions-url]\n\n[crates-badge]: https://img.shields.io/crates/v/heavykeeper.svg\n[crates-url]: https://crates.io/crates/heavykeeper\n[license-badge]: https://img.shields.io/crates/l/heavykeeper.svg\n[license-url]: https://github.com/pmcgleenon/heavykeeper-rs/blob/master/LICENSE\n[actions-badge]: https://github.com/pmcgleenon/heavykeeper-rs/actions/workflows/rust.yml/badge.svg\n[actions-url]: https://github.com/pmcgleenon/heavykeeper-rs/actions?query=workflow%3Arust+branch%3Amain\n\n\n[📖 Docs](https://docs.rs/heavykeeper)\n\nTop-K Heavykeeper algorithm for Top-K elephant flows\n\nThis is based on the [paper](https://www.usenix.org/system/files/conference/atc18/atc18-gong.pdf)\nHeavyKeeper: An Accurate Algorithm for Finding Top-k Elephant Flows\nby Junzhi Gong, Tong Yang, Haowei Zhang, and Hao Li, Peking University;\nSteve Uhlig, Queen Mary, University of London; Shigang Chen, University of Florida;\nLorna Uden, Staffordshire University; Xiaoming Li, Peking University\n\n# Example\n\nSee [examples/basic.rs](examples/basic.rs) for a complete example, or [examples/ip_files.rs](examples/ip_files.rs) for an example of counting top-k IP flows in a file.\n\nBasic usage:\n```rust\nuse heavykeeper::TopK;\n\n// create a new TopK with k=10, width=1000, depth=4, decay=0.9\nlet mut topk: TopK\u003cString\u003e = TopK::new(10, 1000, 4, 0.9);\n\n// add some items\ntopk.add(\"example item\", 5);\ntopk.add(\"another item\", 1);\n\n// check the counts\nfor node in topk.list() {\n    println!(\"{} {}\", node.item, node.count);\n}\n```\n\n# Variants\n\nThe crate ships three top-K sketches that share the same public API\n(`new` / `with_seed` / `with_hasher` / `builder` / `add` / `count` /\n`query` / `list` / `merge`):\n\n| Sketch          | Layout                                           | Insert throughput on Zipf(s=1.2), 1M | Recall @ φ=0.0005 |\n| --------------- | ------------------------------------------------ | -----------------------------------: | ----------------: |\n| `TopK`          | `depth` independent rows × `width` buckets        |                       21.0 Melem / s |             0.942 |\n| `BucketedTopK`  | one bucket of `depth` cells per key               |                       29.0 Melem / s |             0.985 |\n| `CuckooTopK`    | per-bucket lobby + `depth` heavy slots, 2-bucket cuckoo |                       29.8 Melem / s |             1.000 |\n\nNumbers are from `cargo bench --bench topk_vs_bucketed` at `K=100,\nwidth=4096, depth=4, decay=0.9` on `u64` keys. Recall is from\n`tests/accuracy_compare.rs` (paper-style heavy-hitter test, φ = 0.0005,\n1 M Zipf samples).\n\n`TopK` is the canonical implementation from the paper, with its\naccuracy bounds. `BucketedTopK` and `CuckooTopK` are derived variants —\nthey don't carry the paper's row-independence accuracy bounds, but the\nempirical accuracy on Zipf streams is competitive and often better.\n\nPick by workload:\n\n- **`TopK`** — when you want the published algorithm and its bounds.\n- **`BucketedTopK`** — best general-purpose insert throughput; closest to `TopK`'s cost model with a single bucket per key.\n- **`CuckooTopK`** — best accuracy *and* throughput on heavy-hitter-skewed traffic (the elephant-flow use case). Each bucket has a single lobby cell with probabilistic decay plus `depth` non-decaying heavy slots; promoted items live in one of two cuckoo candidate buckets and are re-homed on collision via a kick chain (bound configurable via `CuckooBuilder::max_kicks`, default 8).\n\nAll three support seedable construction, custom hashers, and `merge`\nbetween compatible instances. Errors are returned via\n`BuilderError`/`MergeError` enums; the infallible constructors\n(`new`, `with_seed`, `with_hasher`) trust the caller. Bucket indexing\nuses an AND-mask fast-path when `width` is a power of two; pick\npower-of-two widths in production for the best per-add cost.\n\n# Real-world packet trace\n\n`examples/ip_files.rs` runs all three sketches over a CAIDA-style trace\n(27.5 M packets, 1.03 M distinct 13-byte flow keys = src IP : src port →\ndst IP : dst port + protocol). Same `K=1000, decay=0.95`, equal cell\nbudgets across variants:\n\n| Sketch          | Width × depth          | Throughput | hit\\_ratio | ARE on reported | ARE on true top-K |\n| --------------- | ---------------------- | ---------: | ---------: | --------------: | ----------------: |\n| `TopK`          | 16384 × 2              | 14.1 Mpps  |     0.9270 |          0.0050 |            0.0745 |\n| `BucketedTopK`  | 8192 × 4               | 18.1 Mpps  |     0.9860 |          0.0035 |            0.0129 |\n| `CuckooTopK`    | 8192 × (1 + 4 heavy)   | 17.0 Mpps  | **0.9990** |      **0.0012** |        **0.0012** |\n\n# Other HeavyKeeper Implementations\n\n| Name                       | Language | Github Repo                                                                  |\n|----------------------------|----------|------------------------------------------------------------------------------|\n| SegmentIO                  | Go       | https://github.com/segmentio/topk                                            |\n| Aegis                      | Go       | https://github.com/go-kratos/aegis/blob/main/topk/heavykeeper.go             |\n| Tomasz Kolaj               | Go       | https://github.com/migotom/heavykeeper                                       |\n| HeavyKeeper Paper          | C++      | https://github.com/papergitkeeper/heavy-keeper-project                       |\n| Jigsaw-Sketch              | C++      | https://github.com/duyang92/jigsaw-sketch-paper/tree/main/CPU/HeavyKeeper    |\n| Redis Bloom Heavykeeper    | C        | https://github.com/RedisBloom/RedisBloom/blob/master/src/topk.c              |\n| Count-Min-Sketch           | Rust     | https://github.com/alecmocatta/streaming_algorithms                          |\n| Sliding Window HeavyKeeper | Go       | https://github.com/keilerkonzept/topk                                        |\n\n# Running\n\n## Word Count Example\n\nA word count program that demonstrates the HeavyKeeper algorithm can be found at [`examples/word_count.rs`](examples/word_count.rs).\n\n### Usage\n```bash\ncargo build --example word_count --release\ntarget/release/examples/word_count -k 10 -w 8192 -d 2 -y 0.95 -f data/war_and_peace.txt\n```\n\n## Running the basic example \n```bash\ncargo run --example basic --release\n```\n\n## Running the IPv4 example \n```bash\ncargo run --example ip_files --release\n```\n\n## Run the benchmarks\n```bash\ncargo bench\n```\n\n## Benchmark the sample word count app\n```bash\nhyperfine 'target/release/examples/word_count -k 10 -w 8192 -d 2 -y 0.95 -f data/war_and_peace.txt'\n```\n\n## Test Data\n\nFor information about test data format and how to obtain or generate test data, please see [data/README.md](data/README.md).\n\n# License\nThis project is dual licensed under the Apache/MIT license.   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmcgleenon%2Fheavykeeper-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmcgleenon%2Fheavykeeper-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmcgleenon%2Fheavykeeper-rs/lists"}