Skip to content

Commit 8348151

Browse files
authored
define SmallHashMap in spacetimedb_data_structures (#4136)
# Description of Changes Defines `SmallHashMap` in `spacetimedb_data_structures`. The data structure is a hybrid map that is backed by a vector and linear scan for the first `M` elements. Then it falls back into a normal hash map. For the first `N` elements, where `N < M`, the vector is stored inline. That is, the vector is a `SmallVec<[(K, V); N>`. The structure is optimized for access patterns where the keys and values are accessed together, therefore, keys and values are not stored separately. # API and ABI breaking changes None, just additive. # Expected complexity level and risk 1 # Testing A comprehensive proptest suite is added for the datastructure.
1 parent cf33ad9 commit 8348151

4 files changed

Lines changed: 405 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/data-structures/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ serde = ["dep:serde", "hashbrown/serde"]
1414
spacetimedb-memory-usage = { workspace = true, optional = true, default-features = false }
1515
ahash.workspace = true
1616
crossbeam-queue.workspace = true
17+
either.workspace = true
1718
hashbrown.workspace = true
1819
nohash-hasher.workspace = true
1920
serde = { workspace = true, optional = true }
2021
smallvec.workspace = true
2122
thiserror.workspace = true
2223

24+
[dev-dependencies]
25+
proptest.workspace = true
26+
2327
[lints]
2428
workspace = true

crates/data-structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pub mod map;
66
pub mod nstr;
77
pub mod object_pool;
88
pub mod slim_slice;
9+
pub mod small_map;

0 commit comments

Comments
 (0)