pub struct Trie { /* private fields */ }Expand description
Standard Trie implementation using arena allocation.
All nodes are stored in a Vec<Node>; children are indices into that vec.
Implementations§
Source§impl Trie
impl Trie
pub fn new() -> Self
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total number of nodes (including root).
Sourcepub fn word_count(&self) -> usize
pub fn word_count(&self) -> usize
Number of distinct words stored.
Sourcepub fn contains_prefix(&self, prefix: &str) -> bool
pub fn contains_prefix(&self, prefix: &str) -> bool
Returns true if prefix is a prefix of any word in the trie.
Sourcepub fn add(&mut self, word: &str, count: usize) -> Result<(), LexError>
pub fn add(&mut self, word: &str, count: usize) -> Result<(), LexError>
Add a word with an optional count (default 1).
Sourcepub fn add_all<I: IntoIterator<Item = String>>(
&mut self,
words: I,
) -> Result<(), LexError>
pub fn add_all<I: IntoIterator<Item = String>>( &mut self, words: I, ) -> Result<(), LexError>
Add all words from an iterator.
Sourcepub fn add_from_file(&mut self, path: &str) -> Result<(), LexError>
pub fn add_from_file(&mut self, path: &str) -> Result<(), LexError>
Add all words from a file (one word per line).
Sourcepub fn search(&self, pattern: &str) -> Result<Vec<String>, LexError>
pub fn search(&self, pattern: &str) -> Result<Vec<String>, LexError>
Return all words matching the wildcard pattern.
? matches exactly one character; * matches zero or more.
Sourcepub fn search_with_count(
&self,
pattern: &str,
) -> Result<Vec<(String, usize)>, LexError>
pub fn search_with_count( &self, pattern: &str, ) -> Result<Vec<(String, usize)>, LexError>
Like search but also returns word counts.
Sourcepub fn search_with_prefix(&self, prefix: &str) -> Vec<String>
pub fn search_with_prefix(&self, prefix: &str) -> Vec<String>
Return all words with the given prefix.
Sourcepub fn search_with_prefix_count(&self, prefix: &str) -> Vec<(String, usize)>
pub fn search_with_prefix_count(&self, prefix: &str) -> Vec<(String, usize)>
Like search_with_prefix but also returns counts.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Trie
impl RefUnwindSafe for Trie
impl Send for Trie
impl Sync for Trie
impl Unpin for Trie
impl UnsafeUnpin for Trie
impl UnwindSafe for Trie
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more