{"id":18026771,"url":"https://github.com/yegor256/emap","last_synced_at":"2025-07-03T20:35:00.024Z","repository":{"id":154063204,"uuid":"631609107","full_name":"yegor256/emap","owner":"yegor256","description":"📈 The fastest map possible in Rust, where keys are integers and the capacity is fixed (faster than Vec!)","archived":false,"fork":false,"pushed_at":"2025-06-22T12:59:57.000Z","size":311,"stargazers_count":12,"open_issues_count":6,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T13:41:59.069Z","etag":null,"topics":["data-structures","hashmap","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/emap","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/yegor256.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2023-04-23T15:05:52.000Z","updated_at":"2025-06-22T13:00:00.000Z","dependencies_parsed_at":"2023-10-11T06:20:48.697Z","dependency_job_id":"3afed0f8-11d3-453c-9d68-ac042b073498","html_url":"https://github.com/yegor256/emap","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/yegor256/emap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Femap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Femap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Femap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Femap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yegor256","download_url":"https://codeload.github.com/yegor256/emap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yegor256%2Femap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261303916,"owners_count":23138276,"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":["data-structures","hashmap","rust"],"created_at":"2024-10-30T08:07:59.178Z","updated_at":"2025-07-03T20:35:00.015Z","avatar_url":"https://github.com/yegor256.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Fastest Map with `usize` Keys and Fixed Capacity\n\n[![cargo](https://github.com/yegor256/emap/actions/workflows/cargo.yml/badge.svg)](https://github.com/yegor256/emap/actions/workflows/cargo.yml)\n[![crates.io](https://img.shields.io/crates/v/emap.svg)](https://crates.io/crates/emap)\n[![codecov](https://codecov.io/gh/yegor256/emap/branch/master/graph/badge.svg)](https://codecov.io/gh/yegor256/emap)\n[![Hits-of-Code](https://hitsofcode.com/github/yegor256/emap)](https://hitsofcode.com/view/github/yegor256/emap)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/emap/blob/master/LICENSE.txt)\n[![docs.rs](https://img.shields.io/docsrs/emap)](https://docs.rs/emap/latest/emap/)\n\nThe [`emap::Map`][Map] is the fastest possible [associative array] in Rust,\n  with `usize` keys.\nIt's by the order of magnitude faster than the standard\n  [`HashMap\u003cusize, V\u003e`][HashMap].\nIt's also faster than [`IntMap`][IntMap] (_we are working on this_).\n\nIt's essentially [`Vec\u003cOption\u003cV\u003e\u003e`][Vec] with two extra features:\n\n  1) `next_key()` with _O(1)_ complexity\n  and\n  2) iterators with _O(M)_ complexity, where _M_ is the number of elements in\nthe array.\n\nYou must know the total capacity upfront.\n\nYou must account for a memory overhead of `2 * usize` per element.\n\nFirst, add this to `Cargo.toml`:\n\n```toml\n[dependencies]\nemap = \"0.0.13\"\n```\n\nThen, use it like a standard hash map... well, almost:\n\n```rust\nuse emap::Map;\nlet mut m : Map\u003c\u0026str\u003e = Map::with_capacity_init(100); // allocation on heap\nm.insert(m.next_key(), \"foo\");\nm.insert(m.next_key(), \"bar\");\nassert_eq!(2, m.len());\n```\n\nIf more than 100 keys will be added to the map, it will panic.\nThe map doesn't increase its size automatically, like [`Vec`][Vec] does\n(this is one of the reasons why we are faster).\n\nRead [the API documentation](https://docs.rs/emap/latest/emap/).\nThe struct [`emap::Map`][Map] is designed as closely similar to\n[`std::collections::HashMap`][HashMap] as possible.\n\n## Benchmark\n\nThere is a summary of a simple benchmark, where we compared `emap::Map` with\n`Intmap`, changing the total capacity `CAP` of them (horizontal axis).\nWe applied the same interactions\n([`benchmark.rs`][benchmark])\nto them both and measured how fast they performed. In the following table,\nthe numbers over 1.0 indicate performance gain of `Map` against `IntMap`,\nwhile the numbers below 1.0 demonstrate performance loss.\n\n\u003c!-- benchmark --\u003e\n| | 4 | 16 | 256 | 4096 |\n| --- | --: | --: | --: | --: |\n| `i ∈ 0..CAP {M.insert(i, \u0026\"Hello, world!\")}` |6.33 |16.46 |23.98 |24.08 |\n| `i ∈ 0..CAP {M.insert(i, \u0026\"大家好\"); s ∈ M.values() {sum += s.len()}}` |4.59 |5.80 |1.02 |0.91 |\n| `i ∈ 0..CAP {M.insert(i, \u002642); s ∈ M.keys() {sum += s}}` |7.51 |7.03 |1.15 |0.90 |\n| `i ∈ 0..CAP {M.insert(i, \u002642); s ∈ M.values() {sum += s}}` |6.31 |6.13 |0.94 |0.76 |\n| `i ∈ 0..CAP {M.insert(i, \u002642)}; M.clear(); M.len();` |4.52 |8.74 |9.45 |10.67 |\n| `i ∈ 0..CAP {M.insert(i, \u002642)}; i ∈ CAP-1..0 {M.remove(\u0026i)}` |5.32 |12.26 |15.57 |14.62 |\n\nThe experiment was performed on 13-05-2025.\n There were 10000 repetition cycles.\n The entire benchmark took 1201s.\n\n\u003c!-- benchmark --\u003e\n\n## How to Contribute\n\nFirst, install [Rust](https://www.rust-lang.org/tools/install) and then:\n\n```bash\ncargo test -vv\n```\n\nIf everything goes well, fork repository, make changes,\nsend us a\n[pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).\nWe will review your changes and apply them to the `master` branch shortly,\nprovided they don't violate our quality standards. To avoid frustration,\nbefore sending us your pull request please run `cargo test` again. Also,\nrun `cargo fmt` and `cargo clippy`.\n\nAlso, before you start making changes, run benchmarks:\n\n```bash\ncargo bench\n```\n\nThen, after the changes you make, run it again. Compare the results.\nIf your changes degrade performance, think twice before submitting\na pull request.\n\n[Map]: https://docs.rs/emap/0.0.13/emap/struct.Map.html\n[HashMap]: https://doc.rust-lang.org/std/collections/struct.HashMap.html\n[Vec]: https://doc.rust-lang.org/std/vec/struct.Vec.html\n[benchmark]: https://github.com/yegor256/emap/blob/master/tests/benchmark.rs\n[associative array]: https://en.wikipedia.org/wiki/Associative_array\n[IntMap]: https://docs.rs/intmap/latest/intmap/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Femap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyegor256%2Femap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyegor256%2Femap/lists"}