indextreemap
IndexTreeMap is an ordered tree map based on the rust standard library BTreeMap, that allows for items to be accessed by key, value, or position in the tree.
This library is meant to serve niche use cases where the deterministic ordering of key-value items is required, with the ability to index items by position or key in logarithmic time.
When compared to the standard library BTreeMap (std::collections::BTreeMap), for operations that require changes in memory allocation (insert, remove, etc...) the IndexTreeMap is slower. However, when referencing data already allocated in memory, the IndexTreeMap is equivalent or faster.
0.2 highlights
Version 0.2 adds APIs for large ordered indexes whose values live behind shared handles:
SharedIndexTreeMap<K, V>gives O(1) snapshot clones by sharing anIndexTreeMapbehind anArc.iter_ref,keys_ref, andvalues_refborrow entries without requiringK: CloneorV: Clone.union_fromandtry_union_frommerge shared maps by key. The checked form rejects duplicate keys with unequal values. These union helpers use a sorted-stream merge and bulk tree builder instead of repeatedly inserting every missing key.IndexTreeMap::try_from_sorted_unique_iterbulk-builds a tree from entries that are already sorted by unique key.hash_keys_orderedstreams ordered keys into a caller-provided digest without building a temporary key buffer.serialize_entries_orderedstreams borrowed key/value pairs to caller-owned serialization code.- The optional
fast-hashfeature enables deterministic XXH3 helpers for non-cryptographic ordered key fingerprints.
For zero-copy payload behavior, store large values as shared handles such as
Arc<T> or byte buffers. Cloning SharedIndexTreeMap does not clone the tree or
payloads. Mutating a shared snapshot currently clones the tree/key structure
before applying the mutation, but shared value handles continue pointing at the
same payloads.
use Arc;
use SharedIndexTreeMap;
let mut map = new;
map.insert;
let snapshot = map.clone;
assert!;
Enable the fast non-cryptographic hasher with:
= { = "0.2", = ["fast-hash"] }