Skip to content

Commit 0ef5dc8

Browse files
committed
Fork indexmap into ringmap, based on VecDeque
1 parent e87a15e commit 0ef5dc8

37 files changed

+2984
-2372
lines changed

.github/workflows/ci.yml

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
push:
3-
branches: [ master ]
3+
branches: [ main ]
44
pull_request:
5-
branches: [ master ]
5+
branches: [ main ]
66
merge_group:
77

88
name: CI
@@ -17,16 +17,14 @@ jobs:
1717
strategy:
1818
matrix:
1919
include:
20-
- rust: 1.63.0 # MSRV
20+
- rust: 1.68.0 # MSRV
2121
features:
2222
- rust: stable
2323
features: arbitrary
2424
- rust: stable
2525
features: quickcheck
2626
- rust: stable
2727
features: rayon
28-
- rust: stable
29-
features: rustc-rayon
3028
- rust: stable
3129
features: serde
3230
- rust: stable
@@ -40,11 +38,6 @@ jobs:
4038

4139
steps:
4240
- uses: actions/checkout@v4
43-
- uses: actions/cache@v4
44-
if: matrix.rust == '1.63.0'
45-
with:
46-
path: ~/.cargo/registry/index
47-
key: cargo-git-index
4841
- uses: dtolnay/rust-toolchain@master
4942
with:
5043
toolchain: ${{ matrix.rust }}
@@ -72,18 +65,13 @@ jobs:
7265
strategy:
7366
matrix:
7467
include:
75-
- rust: 1.63.0
68+
- rust: 1.68.0
7669
target: thumbv6m-none-eabi
7770
- rust: stable
7871
target: thumbv6m-none-eabi
7972

8073
steps:
8174
- uses: actions/checkout@v4
82-
- uses: actions/cache@v4
83-
if: matrix.rust == '1.63.0'
84-
with:
85-
path: ~/.cargo/registry/index
86-
key: cargo-git-index
8775
- uses: dtolnay/rust-toolchain@master
8876
with:
8977
toolchain: ${{ matrix.rust }}
@@ -121,12 +109,8 @@ jobs:
121109
runs-on: ubuntu-latest
122110
steps:
123111
- uses: actions/checkout@v4
124-
- uses: actions/cache@v4
125-
with:
126-
path: ~/.cargo/registry/index
127-
key: cargo-git-index
128112
- uses: dtolnay/rust-toolchain@nightly
129-
- uses: dtolnay/rust-toolchain@1.63.0 # MSRV
113+
- uses: dtolnay/rust-toolchain@1.68.0 # MSRV
130114
- uses: taiki-e/install-action@v2
131115
with:
132116
tool: cargo-hack

Cargo.toml

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
2-
name = "indexmap"
2+
name = "ringmap"
33
edition = "2021"
4-
version = "2.7.1"
5-
documentation = "https://docs.rs/indexmap/"
6-
repository = "https://github.com/indexmap-rs/indexmap"
4+
version = "0.1.0"
5+
documentation = "https://docs.rs/ringmap/"
6+
repository = "https://github.com/indexmap-rs/ringmap"
77
license = "Apache-2.0 OR MIT"
8-
description = "A hash table with consistent order and fast iteration."
8+
description = "A hash table with consistent deque-like order and fast iteration."
99
keywords = ["hashmap", "no_std"]
1010
categories = ["data-structures", "no-std"]
11-
rust-version = "1.63"
11+
rust-version = "1.68"
1212

1313
[lib]
1414
bench = false
@@ -22,10 +22,6 @@ serde = { version = "1.0", optional = true, default-features = false }
2222
borsh = { version = "1.2", optional = true, default-features = false }
2323
rayon = { version = "1.9", optional = true }
2424

25-
# Internal feature, only used when building as part of rustc,
26-
# not part of the stable interface of this crate.
27-
rustc-rayon = { package = "rustc-rayon", version = "0.5", optional = true }
28-
2925
[dependencies.hashbrown]
3026
version = "0.15.0"
3127
default-features = false
@@ -49,7 +45,7 @@ test_debug = []
4945
debug = true
5046

5147
[package.metadata.release]
52-
allow-branch = ["master"]
48+
allow-branch = ["main"]
5349
sign-tag = true
5450
tag-name = "{{version}}"
5551

README.md

+23-41
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,41 @@
1-
# indexmap
1+
# ringmap
22

3-
[![build status](https://github.com/indexmap-rs/indexmap/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/indexmap-rs/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.63%2B-orange.svg)](https://img.shields.io/badge/rust-1.63%2B-orange.svg)
3+
[![build status](https://github.com/indexmap-rs/ringmap/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/indexmap-rs/ringmap/actions)
4+
[![crates.io](https://img.shields.io/crates/v/ringmap.svg)](https://crates.io/crates/ringmap)
5+
[![docs](https://docs.rs/ringmap/badge.svg)](https://docs.rs/ringmap)
6+
[![rustc](https://img.shields.io/badge/rust-1.68%2B-orange.svg)](https://img.shields.io/badge/rust-1.68%2B-orange.svg)
77

8-
A pure-Rust hash table which preserves (in a limited sense) insertion order.
8+
A pure-Rust hash table which preserves (in a limited sense) insertion order,
9+
with efficient deque-like manipulation of both the front and back ends.
910

1011
This crate implements compact map and set data-structures,
1112
where the iteration order of the keys is independent from their hash or
12-
value. It preserves insertion order (except after removals), and it
13+
value. It preserves insertion order in most mutating operations, and it
1314
allows lookup of entries by either hash table key or numerical index.
1415

15-
Note: this crate was originally released under the name `ordermap`,
16-
but it was renamed to `indexmap` to better reflect its features.
17-
The [`ordermap`](https://crates.io/crates/ordermap) crate now exists
18-
as a wrapper over `indexmap` with stronger ordering properties.
19-
2016
# Background
2117

22-
This was inspired by Python 3.6's new dict implementation (which remembers
23-
the insertion order and is fast to iterate, and is compact in memory).
24-
25-
Some of those features were translated to Rust, and some were not. The result
26-
was indexmap, a hash table that has following properties:
18+
This crate was forked from [`indexmap`](https://crates.io/crates/indexmap),
19+
with the primary difference being a change from `Vec` to `VecDeque` for the
20+
primary item storage. As a result, it has many of the same properties, as
21+
well as a few new ones:
2722

2823
- Order is **independent of hash function** and hash values of keys.
2924
- Fast to iterate.
3025
- Indexed in compact space.
31-
- Preserves insertion order **as long** as you don't call `.remove()`,
32-
`.swap_remove()`, or other methods that explicitly change order.
33-
The alternate `.shift_remove()` does preserve relative order.
26+
- Efficient pushing and popping from both the front and back.
27+
- Preserves insertion order **as long** as you don't call `.swap_remove_back()`
28+
or other methods that explicitly change order.
29+
- In `ringmap`, the regular `.remove()` **does** preserve insertion order,
30+
equivalent to what `indexmap` calls `.shift_remove()`.
3431
- Uses hashbrown for the inner table, just like Rust's libstd `HashMap` does.
3532

36-
## Performance
37-
38-
`IndexMap` derives a couple of performance facts directly from how it is constructed,
39-
which is roughly:
40-
41-
> A raw hash table of key-value indices, and a vector of key-value pairs.
42-
43-
- Iteration is very fast since it is on the dense key-values.
44-
- Removal is fast since it moves memory areas only in the table,
45-
and uses a single swap in the vector.
46-
- Lookup is fast-ish because the initial 7-bit hash lookup uses SIMD, and indices are
47-
densely stored. Lookup also is slow-ish since the actual key-value pairs are stored
48-
separately. (Visible when cpu caches size is limiting.)
49-
50-
- In practice, `IndexMap` has been tested out as the hashmap in rustc in [PR45282] and
51-
the performance was roughly on par across the whole workload.
52-
- If you want the properties of `IndexMap`, or its strongest performance points
53-
fits your workload, it might be the best hash table implementation.
54-
55-
[PR45282]: https://github.com/rust-lang/rust/pull/45282
33+
`ringmap` also follows [`ordermap`](https://crates.io/crates/ordermap) in using
34+
its entry order for `PartialEq` and `Eq`, whereas `indexmap` considers the same
35+
entries in *any* order to be equal for drop-in compatibility with `HashMap`
36+
semantics. Using the order is faster, and also allows `ringmap` to implement
37+
`PartialOrd`, `Ord`, and `Hash`.
5638

5739
# Recent Changes
5840

59-
See [RELEASES.md](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md).
41+
See [RELEASES.md](https://github.com/indexmap-rs/ringmap/blob/main/RELEASES.md).

0 commit comments

Comments
 (0)