pub struct Trie { /* private fields */ }Expand description
Recursively-defined prefix trie. Typically constructed with Trie::new() for the root node,
then insert()ed into many times. Querying for simple existence of a word in the Trie can be
performed with contains().
More advanced usage includes using find() to find sub-Trie structures to efficiently search
for existince of many words with similar prefixes. See
https://github.com/glennhartmann/aoc24/blob/fa21b5787382765a598381c3a0583258b645dc86/src/days/day_19.rs
for an example.
Empty strings are considered to exist in every Trie by default.
Implementations§
Source§impl Trie
impl Trie
Sourcepub fn with_prefix(s: &str, is_terminal: bool) -> Self
pub fn with_prefix(s: &str, is_terminal: bool) -> Self
Create a sub-node with an existing prefix, whether terminal or not, or can be used to create a root node which does not contain the empty string.
Sourcepub fn find(&self, word: &str) -> Option<&Self>
pub fn find(&self, word: &str) -> Option<&Self>
Find the node within the Trie described by word. Note that the returned node may not be
terminal. Can be used as any other Trie, for example to continue searching for many
suffixes that share the same prefix.