Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A hash table with consistent order and fast iteration; access items by key or sequence index

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

indexmap-rs/indexmap

Repository files navigation

build statuscrates.iodocsrustc

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 orvalue. It preserves insertion order (except after removals), and itallows lookup of entries by either hash table key or numerical index.

Note: this crate was originally released under the nameordermap,but it was renamed toindexmap to better reflect its features.Theordermap crate now existsas a wrapper overindexmap with stronger ordering properties.

Background

This was inspired by Python 3.6's new dict implementation (which remembersthe 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 resultwas indexmap, a hash table that has following properties:

  • Order isindependent of hash function and hash values of keys.
  • Fast to iterate.
  • Indexed in compact space.
  • Preserves insertion orderas long as you don't call.remove(),.swap_remove(), or other methods that explicitly change order.The alternate.shift_remove() does preserve relative order.
  • Uses hashbrown for the inner table, just like Rust's libstdHashMap 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 aredensely stored. Lookup also is slow-ish since the actual key-value pairs are storedseparately. (Visible when cpu caches size is limiting.)

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

  • If you want the properties ofIndexMap, or its strongest performance pointsfits your workload, it might be the best hash table implementation.

Recent Changes

SeeRELEASES.md.

About

A hash table with consistent order and fast iteration; access items by key or sequence index

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp