tried
A fast, compact double-array trie with no_std + alloc support. Fork of yada providing O(key-length) exact-match and common-prefix search over a flat, cache-friendly byte buffer (4 bytes per node).
Features
no_std— only requiresalloc- Compact — 4 bytes per node in a single contiguous buffer
- Fast — O(key-length) lookups via double-array indexing
- Zero-allocation iteration —
common_prefix_searchreturns a lazy iterator
Examples
Exact-match lookup
Build a trie from sorted key-value pairs, then look up keys in O(key-length) time. Keys must be sorted lexicographically and must not contain NUL bytes.
use ;
// Keys must be sorted and unique.
let keyset: & = &;
let bytes = build.unwrap;
let da = new;
assert_eq!;
assert_eq!;
// String keys work too (anything implementing AsRef<[u8]>).
assert_eq!;
Common-prefix search
Find all keys that are prefixes of a given input. Returns (value, prefix_length) pairs in ascending length order.
use ;
let keyset: & = &;
let bytes = build.unwrap;
let da = new;
let matches: = da.common_prefix_search.collect;
// All four keys are prefixes of "rustacean":
// "r" → (value=0, len=1)
// "ru" → (value=1, len=2)
// "rus" → (value=2, len=3)
// "rust" → (value=3, len=4)
assert_eq!;
Zero-copy with borrowed data
DoubleArray is generic over any Deref<Target = [u8]>, so you can use borrowed slices to avoid copies.
use ;
let keyset: & = &;
let bytes = build.unwrap;
// Borrow the built bytes instead of moving them.
let da = new;
assert_eq!;
License
MIT OR Apache-2.0