Go to file
openharmony_ci 176481e74d
!3 告警与遗留问题文件补充
Merge pull request !3 from peizhe/master
2023-05-09 11:13:35 +00:00
.github/workflows impl Arbitrary for IndexMap and IndexSet 2022-11-17 13:00:27 -08:00
benches Use prelude FromIterator 2022-06-16 16:22:28 -07:00
src impl Arbitrary for IndexMap and IndexSet 2022-11-17 13:00:27 -08:00
test-nostd Use prelude FromIterator 2022-06-16 16:22:28 -07:00
test-serde Prepare for indexmap 1.9.0, with MSRV 1.56 2022-06-16 16:19:06 -07:00
tests Use u8 test indices so quickcheck is less likely to go out of bounds. 2022-06-16 16:40:05 -07:00
.gitignore Adds a OrderMap::drain() method 2017-04-20 13:21:57 -07:00
.rustfmt.toml Prepare for indexmap 1.9.0, with MSRV 1.56 2022-06-16 16:19:06 -07:00
BUILD.gn Add GN Build Files and Custom Modifications 2023-04-18 18:30:39 +08:00
build.rs Assume support for const-generics 2022-06-16 16:21:36 -07:00
Cargo.toml Release 1.9.2 2022-11-17 13:01:39 -08:00
LICENSE-APACHE Add License files 2017-08-01 20:37:49 +02:00
LICENSE-MIT Add License files 2017-08-01 20:37:49 +02:00
OAT.xml 告警与遗留问题文件补充 2023-05-08 15:16:58 +08:00
README.md Revert "Bump MSRV to 1.56.1, matching hashbrown as of 0.12.1" 2022-06-21 10:25:01 -07:00
README.OpenSource CI OAT 告警清零与README.OpenSource 中License信息整改 2023-05-04 09:31:42 +08:00
RELEASES.md Add an Arbitrary release note 2022-11-17 13:01:11 -08:00

indexmap

build status crates.io docs rustc

A pure-Rust hash table which preserves (in a limited sense) insertion order.

This crate implements compact map and set data-structures, where the iteration order of the keys is independent from their hash or value. It preserves insertion order (except after removals), and it allows lookup of entries by either hash table key or numerical index.

Note: this crate was originally released under the name ordermap, but it was renamed to indexmap to better reflect its features.

Background

This was inspired by Python 3.6's new dict implementation (which remembers the insertion order and is fast to iterate, and is compact in memory).

Some of those features were translated to Rust, and some were not. The result was indexmap, a hash table that has following properties:

  • Order is independent of hash function and hash values of keys.
  • Fast to iterate.
  • Indexed in compact space.
  • Preserves insertion order as long as you don't call .remove().
  • Uses hashbrown for the inner table, just like Rust's libstd HashMap does.

Performance

IndexMap derives a couple of performance facts directly from how it is constructed, which is roughly:

A raw hash table of key-value indices, and a vector of key-value pairs.

  • Iteration is very fast since it is on the dense key-values.

  • Removal is fast since it moves memory areas only in the table, and uses a single swap in the vector.

  • Lookup is fast-ish because the initial 7-bit hash lookup uses SIMD, and indices are densely stored. Lookup also is slow-ish since the actual key-value pairs are stored separately. (Visible when cpu caches size is limiting.)

  • In practice, IndexMap has been tested out as the hashmap in rustc in PR45282 and the performance was roughly on par across the whole workload.

  • If you want the properties of IndexMap, or its strongest performance points fits your workload, it might be the best hash table implementation.

Recent Changes

See RELEASES.md.