| Crates.io | trie_hard_rs |
| lib.rs | trie_hard_rs |
| version | 0.1.0 |
| created_at | 2025-09-15 06:42:14.9831+00 |
| updated_at | 2025-09-15 06:42:14.9831+00 |
| description | Fast, memory-efficient Trie (prefix tree) implementation with autocomplete support - Rust implementation |
| homepage | https://github.com/GhostVox/trie_hard/tree/main/rust |
| repository | https://github.com/GhostVox/trie_hard |
| max_upload_size | |
| id | 1839498 |
| size | 85,697 |
A blazing fast, memory-efficient Trie (prefix tree) implementation for Rust with autocomplete support.
Part of the trie_hard family - high-performance Trie implementations across multiple programming languages.
This repository contains Trie implementations for multiple languages, each optimized for its respective ecosystem:
More languages coming soon!
This Rust implementation delivers exceptional performance:
Add to your Cargo.toml:
[dependencies]
trie_hard_rs = "0.1"
Basic usage:
use trie_hard_rs::Trie;
let mut trie = Trie::new();
// Insert words with associated values
trie.insert("cat", &1);
trie.insert("car", &2);
trie.insert("card", &3);
// Fast lookups
assert_eq!(trie.get("cat"), Some(&1));
// Prefix search
assert!(trie.prefix_search("ca"));
// Autocomplete
let suggestions = trie.auto_complete("ca", 10);
// Returns: ["cat", "car", "card"]
Clone type as valuesadd_word_list with value generatorsRun benchmarks with:
cargo bench
View detailed HTML reports at target/criterion/report/index.html
let words = ["cat", "car", "card"];
trie.add_word_list(&words, |word| word.len());
// Inserts with word length as value
let mut trie: Trie<(u32, String)> = Trie::new();
trie.insert("word", &(42, "metadata".to_string()));
// Get up to 5 suggestions
let suggestions = trie.auto_complete("prefix", 5);
// Get all suggestions (no limit)
let all_suggestions = trie.auto_complete("prefix", usize::MAX);
// String values
let mut string_trie = Trie::new();
string_trie.insert("key", &"value".to_string());
// Numeric values for scoring/ranking
let mut scored_trie = Trie::new();
scored_trie.insert("popular", &100);
scored_trie.insert("common", &50);
// Complex data structures
#[derive(Clone)]
struct WordData {
frequency: u32,
category: String,
}
let mut data_trie = Trie::new();
data_trie.insert("example", &WordData {
frequency: 42,
category: "noun".to_string(),
});
new() - Create a new empty Trieinsert(key, value) - Insert a key-value pairget(key) - Get value by exact key matchdelete(key) - Remove a key and its valueprefix_search(prefix) - Check if any words start with prefixauto_complete(prefix, max_results) - Get words starting with prefixadd_word_list(words, value_generator) - Insert multiple words with generated valuesTime Complexity:
Space Complexity: O(ALPHABET_SIZE * N * M) where N = number of nodes, M = average key length
While each implementation is optimized for its language, they share:
The trie_hard family was created to provide:
| Feature | trie_hard | Other Crates |
|---|---|---|
| Autocomplete with limits | ✅ | ❌ |
| Generic value types | ✅ | Limited |
| Comprehensive benchmarks | ✅ | Limited |
| Unicode support | ✅ | Varies |
| Batch operations | ✅ | ❌ |
| Sub-microsecond autocomplete | ✅ | ❌ |
Licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request to the main repository.
# Run tests
cargo test
# Run benchmarks
cargo bench
# Check formatting
cargo fmt --check
# Run lints
cargo clippy