xtri

Crates.ioxtri
lib.rsxtri
version0.1.1
created_at2025-08-08 12:26:01.051853+00
updated_at2025-08-08 12:29:55.005929+00
descriptionA fast, memory-efficient radix tree (compressed trie) implementation in Rust with UTF-8 support
homepagehttps://github.com/oramasearch/xtri
repositoryhttps://github.com/oramasearch/xtri
max_upload_size
id1786702
size90,916
Tommaso Allevi (allevo)

documentation

https://docs.rs/xtri

README

xtri

Crates.io Documentation CI

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_prefix and search_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

Usage

use xtri::{RadixTree, SearchMode};

fn main() {
    let mut tree = RadixTree::new();

    // Insert key-value pairs
    tree.insert("application", "main app");
    tree.insert("app", "short form");
    tree.insert("apple", "fruit");
    tree.insert("apply", "verb");
    tree.insert("approach", "method");
    tree.insert("appropriate", "suitable");

    // Search by prefix - returns all keys starting with "app"
    let iter = tree.search_iter("app", SearchMode::Prefix);
    for (key, value) in iter {
        println!("  {} -> {}", String::from_utf8_lossy(&key), value);
    }
    // Output:
    //   apple: fruit
    //   application: main app
    //   apply: verb

    // Update existing value or create a new one
    tree.mut_value("app", |value| {
        *value = Some("short form");
    });

    let iter = tree.search_iter("app", SearchMode::Exact);
    for (key, value) in iter {
        println!("  {} -> {}", String::from_utf8_lossy(&key), value);
    }
    // Output:
    //   app -> short form
}
Commit count: 0

cargo fmt