Crates.io | h3o-ice |
lib.rs | h3o-ice |
version | 0.1.3 |
source | src |
created_at | 2023-09-11 05:01:33.405531 |
updated_at | 2024-03-25 23:29:06.977741 |
description | Frozen{Map,Set} for H3 cells, based on finite state transducers. |
homepage | https://docs.rs/h3o-ice |
repository | https://github.com/HydroniumLabs/h3o-ice |
max_upload_size | |
id | 969247 |
size | 142,924 |
Those data structures are built on top of finite state transducers, which allows them to be extremely compact while offering fast lookup.
This is especially for read-only indexes (both in-memory or on-disk).
cargo install h3o-ice
use h3o::{LatLng, Resolution};
use h3o_ice::FrozenSet;
let coord = LatLng::new(48.872280706 2.332697839).expect("valid coord");
let set = FrozenSet::try_from_iter(
coord.to_cell(Resolution::Nine)
.children(Resolution::Ten)
)
.expect("failed to create set");
set.contains(CellIndex::try_from(0x8a1fb4666417fff).expect("valid cell"));
Frozen{Set,Map} |
BTree{Set,Map} |
Hash{Set,Map} |
|
---|---|---|---|
Memory overhead | ✅ (negative 1) | ❌ (50%2) | ❌ (12-125%2) |
Search complexity | O(key size) | O(log #items) | O(1) |
Range query | ✅ | ✅ | ❌ |
Prefix lookup | ✅ | ❌ | ❌ |
Insertion/Deletion | ❌ | ✅ | ✅ |
Direct lookup | 163 ns | 55 ns | 19 ns |
Compacted lookup | 67 ns | 401 ns | 125 ns |
About the lookup time:
You can run the provided benchmarks to get measures relevant to your machine.
To sum up:
HashSet
for maximum speed.BTreeSet
.FrozenSet
is your friend.Frozen{Map,Set}
are not general purpose data structures. They come with a
bunch of extra constraints (read-only, must be build from pre-sorted input, ...)
but they really shine in their niche and provides a bunch a goodies (e.g. key
compressions, can be mmap'd, prefix lookup, ...).
Frozen{Set,Map}
compresses both common prefixes and suffixes of keys, resulting in a smaller size than the input data set (e.g. the 333MB test dataset fits into a 176KB FrozenSet
) ↩