Module: trie
Contents
StructsTrie- A prefix tree (trie) for efficient string storage and retrieval.
rabin_karp- Rabin-Karp string pattern matching using rolling hash.
resq_dsa::trie::Trie
Struct A prefix tree (trie) for efficient string storage and retrieval. Supports insertion, exact search, and prefix-based autocomplete. All operations are O(m) where m is the length of the string.Use Cases
- Autocomplete suggestions
- IP address routing tables
- Spell checking
- Word frequency tracking
Examples
fn new() -> Self- Creates a new empty Trie.fn insert(self: & mut Self, word: &str)- Inserts a word into the trie.fn search(self: &Self, word: &str) -> bool- Returnstrueif the exact word exists in the trie.fn starts_with(self: &Self, prefix: &str) -> Vec<String>- Returns all words in the trie that start with the given prefix.
- Default
fn default() -> Self
resq_dsa::trie::rabin_karp
Function Rabin-Karp string pattern matching using rolling hash. Finds all occurrences ofpattern in text using a polynomial
rolling hash with modular arithmetic. Average case O(n + m).
The algorithm operates on char boundaries, so it is
Unicode-aware (multi-byte characters are handled correctly).
Arguments
text- The text to search inpattern- The pattern to search for