xtri
A Rust library that implements a radix tree (compressed trie) data structure for efficient string storage and prefix-based searching.
Features
- Generic radix tree structure
RadixTree<T>supporting any value type - Insert key-value pairs with automatic node compression and splitting
- Prefix-based search returning all matching key-value pairs (
search_prefixandsearch_iter) - Mutable value access through closures for safe modification (
mut_value) - Alphabetical ordering of search results
- Full UTF-8 support including emojis and international characters
- Tree merging with customizable conflict resolution
- Parallel sorted bulk insertion for high-performance data loading (optional
parallelfeature)
Usage
use ;
Merging Trees
Efficiently combine two radix trees with customizable conflict resolution:
use ;
let mut tree1 = new;
tree1.insert;
tree1.insert;
let mut tree2 = new;
tree2.insert; // Conflicting key
tree2.insert;
// Merge trees, keeping the second value on conflict
let merged = tree1.merge;
assert_eq!;
Parallel Sorted Bulk Insertion
For large datasets that are already sorted, use the parallel build feature for significant performance improvements (requires parallel feature):
[]
= { = "0.1", = ["parallel"] }
use RadixTree;
// Generate sorted data (or use your own pre-sorted data)
let items: =
.map
.collect;
// Build tree in parallel (5-20x faster than sequential insertion for large datasets)
let tree = from_sorted_parallel;
// Use the tree normally
assert_eq!;
Performance: For 10,000+ sorted keys on multi-core systems, parallel build provides 5-20x speedup compared to sequential insertion.