• Home
Name
Date
Size
#Lines
LOC

..--

.github/workflows/03-May-2024-115106

benches/03-May-2024-950827

src/03-May-2024-7,1224,714

tests/03-May-2024-677552

.cargo_vcs_info.jsonD03-May-202494 66

.gitignoreD03-May-202418 32

.rustfmt.tomlD03-May-202417 21

Android.bpD03-May-20242 KiB6460

Cargo.tomlD03-May-20242 KiB10887

Cargo.toml.origD03-May-20241.6 KiB6652

LICENSED03-May-20241 KiB2622

LICENSE-APACHED03-May-202410.6 KiB202169

LICENSE-MITD03-May-20241 KiB2622

METADATAD03-May-2024642 2422

MODULE_LICENSE_MITD03-May-20240

OWNERSD03-May-202447 21

README.mdD03-May-20242.5 KiB5639

RELEASES.mdD03-May-202412.5 KiB385248

build.rsD03-May-2024291 97

cargo2android.jsonD03-May-202461 65

README.md

1# indexmap
2
3[![build status](https://github.com/bluss/indexmap/workflows/Continuous%20integration/badge.svg?branch=master)](https://github.com/bluss/indexmap/actions)
4[![crates.io](https://img.shields.io/crates/v/indexmap.svg)](https://crates.io/crates/indexmap)
5[![docs](https://docs.rs/indexmap/badge.svg)](https://docs.rs/indexmap)
6[![rustc](https://img.shields.io/badge/rust-1.56%2B-orange.svg)](https://img.shields.io/badge/rust-1.56%2B-orange.svg)
7
8A pure-Rust hash table which preserves (in a limited sense) insertion order.
9
10This crate implements compact map and set data-structures,
11where the iteration order of the keys is independent from their hash or
12value. It preserves insertion order (except after removals), and it
13allows lookup of entries by either hash table key or numerical index.
14
15Note: this crate was originally released under the name `ordermap`,
16but it was renamed to `indexmap` to better reflect its features.
17
18# Background
19
20This was inspired by Python 3.6's new dict implementation (which remembers
21the insertion order and is fast to iterate, and is compact in memory).
22
23Some of those features were translated to Rust, and some were not. The result
24was indexmap, a hash table that has following properties:
25
26- Order is **independent of hash function** and hash values of keys.
27- Fast to iterate.
28- Indexed in compact space.
29- Preserves insertion order **as long** as you don't call `.remove()`.
30- Uses hashbrown for the inner table, just like Rust's libstd `HashMap` does.
31
32## Performance
33
34`IndexMap` derives a couple of performance facts directly from how it is constructed,
35which is roughly:
36
37> A raw hash table of key-value indices, and a vector of key-value pairs.
38
39- Iteration is very fast since it is on the dense key-values.
40- Removal is fast since it moves memory areas only in the table,
41  and uses a single swap in the vector.
42- Lookup is fast-ish because the initial 7-bit hash lookup uses SIMD, and indices are
43  densely stored. Lookup also is slow-ish since the actual key-value pairs are stored
44  separately. (Visible when cpu caches size is limiting.)
45
46- In practice, `IndexMap` has been tested out as the hashmap in rustc in [PR45282] and
47  the performance was roughly on par across the whole workload.
48- If you want the properties of `IndexMap`, or its strongest performance points
49  fits your workload, it might be the best hash table implementation.
50
51[PR45282]: https://github.com/rust-lang/rust/pull/45282
52
53# Recent Changes
54
55See [RELEASES.md](https://github.com/bluss/indexmap/blob/master/RELEASES.md).
56