Rust hash map and set that keep insertion order and index entries
open sourceApache-2.0 OR MITfree
indexmap is a pure-Rust hash table whose iteration order doesn't depend on the keys' hashes: it keeps insertion order (until you remove entries in a way that reorders them) and lets you look entries up by key or by numerical index. It was inspired by Python 3.6's compact dict, stores a raw hash table of indices beside a vector of key-value pairs, and uses hashbrown for the inner table as the standard library's HashMap does, so iteration is very fast. It works without std. It was first released as ordermap, which now exists as a wrapper over it with stronger ordering guarantees.
Problems it solves
- keep a Rust HashMap's keys in the order I inserted them
- get a hash map entry in Rust by its position as well as its key
- iterate over a large Rust map quickly in a stable order
Features
- IndexMap and IndexSet keep insertion order
- Look entries up by key or by numerical index
- Fast iteration over densely stored entries
- shift_remove keeps relative order; swap_remove is faster
- Works in no_std environments
Limitations
- Insertion order isn't kept after swap_remove or other methods that explicitly reorder entries.1
Alternatives
The same job
These do what indexmap does.
