• Stars
    star
    1,361
  • Rank 34,534 (Top 0.7 %)
  • Language
    Rust
  • License
    Other
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

arrayvec

A vector with a fixed capacity. (Rust)
Rust
714
star
2

scopeguard

Rust crate for a convenient RAII scope guard.
Rust
429
star
3

maplit

Rust container / collection literal macros for HashMap, HashSet, BTreeMap, BTreeSet.
Rust
378
star
4

either

The enum Either with variants Left and Right is a general purpose sum type with two cases.
Rust
377
star
5

matrixmultiply

General matrix multiplication of f32 and f64 matrices in Rust. Supports matrices with general strides.
Rust
206
star
6

indexing

Sound unchecked indexing using “generativity”; a type system approach to indices, pointers and ranges that are trusted to be in bounds.
Rust
100
star
7

bencher

bencher is just a port of the libtest (unstable) benchmark runner to Rust stable releases. `cargo bench` on stable. "Not a better bencher!" = No feature development. Go build a better stable benchmarking library.
Rust
83
star
8

twoway

Twoway / Fast substring search for strings and byte strings (Rust) / Also assorted benchmarks and string search snippets
Rust
65
star
9

permutohedron

Rust
36
star
10

rustfaq

Bluss' Rust FAQ, intended to answer questions that are often encountered, and being simple to update. There's quite a lot of editing needed to get to a useful FAQ, so we'll see if we get there.
30
star
11

odds

Odds and ends — collection miscellania. Extra functionality for slices, strings and other things
Rust
21
star
12

fast-floats

Experimental (unstable) “fast-math” wrappers for f32, f64
Rust
19
star
13

pyproject-local-kernel

Python Jupyter kernel using pyproject environment manangers like Rye, Uv, PDM, Poetry, Hatch etc.
Python
15
star
14

defmac

A macro to define lambda-like macros inline.
Rust
15
star
15

ixlist

The “ixlist” is a linked list in a vector
Rust
11
star
16

itertools-num

[looking for adoption of the crate] Numerics iterator tools; cumulative sum and linearly spaced floats and such.
Rust
10
star
17

debugit

DebugIt: Use specialization so you can debug-print a value without explicit (and viral) Debug trait bound. (Not really maintained. Uses specialization so it may break)
Rust
10
star
18

thread-tree

A tree-shaped thread pool used for spawning stack-bound scoped jobs with no work stealing. Derived from a little bit of rayon-core code + new thread pool on top.
Rust
10
star
19

tox-rye

Use Rye to discover or fetch Python versions for Tox (v4)
Python
7
star
20

unchecked-index

Unchecked indexing and debug-assertion checked indexing through the regular index syntax.
Rust
7
star
21

qc.rs

quickcheck for Rust
Rust
6
star
22

simplesvg

Very simple drawing/diagramming library with svg output (Rust).
Rust
6
star
23

virtualenv-rye-discovery

Virtualenv plugin for discovery of Python interpreters through Rye.
Python
5
star
24

ryeish-kernel

Python Jupyter kernel using Rye for reproducible notebooks
Python
5
star
25

knuth-morris-pratt

Generic substring search for sequences. Requires elements that are equality comparable.
Rust
5
star
26

galil-seiferas

Galil-Seiferas algorithm: String search in constant space, linear time, for nonorderable alphabets
Rust
5
star
27

rawpointer

Extra methods for raw pointers
Rust
4
star
28

dlx

Dancing Links (“dlx”) solver for the exact cover problem, written in Rust. Can be used to create a sudoku solver.
Rust
4
star
29

rpasha

Restrictive Precise Angle Shadowcasting, a field of view algorithm for a discrete playing field.
Rust
4
star
30

rawslice

Rust
2
star
31

siphash-ppc-altivec

C
2
star
32

asprim

Rust library with a trait for the `as` operator for primitive numeric types.
Rust
2
star
33

blake2-ppc-altivec

BLAKE2s hash function https://blake2.net PowerPC/Altivec implementation by Ulrik Sverdrup
C
2
star
34

trait-group

Rust
2
star
35

blis-sys

[Feel free to adopt/fork this repo!] Experimental Rust bindings for BLIS
Rust
2
star
36

bmap

Experimental B-tree map in Rust using ArrayVec
Rust
1
star
37

rand_derive

(Obsolete) derive(Rand) for use with custom_derive!{}. Works with stable Rust 1.8+
Rust
1
star
38

numeric-loops

Rust
1
star
39

complexfloat

Extended traits for Rust Float and Complex types. Requires Rust 1.8.
Rust
1
star
40

bluss.github.io

HTML
1
star