pub struct Trie { /* private fields */ }
Expand description
A Trie (prefix tree) data structure for efficient string prefix matching.
A Trie stores a set of strings in a tree structure, where each node represents a character in a string,
and paths from the root to nodes marked as is_end_of_word
represent complete words.
Implementations§
Source§impl Trie
impl Trie
Sourcepub fn insert(&mut self, word: &str)
pub fn insert(&mut self, word: &str)
Inserts a word into the Trie
.
This method iterates over the characters of the word, creating new nodes or following existing ones as needed.
The is_end_of_word
flag is set to true
on the last node to mark the end of the inserted word.
Sourcepub fn search_prefix(&mut self, word: &str) -> bool
pub fn search_prefix(&mut self, word: &str) -> bool
Searches for a prefix in the Trie
.
Returns true
if the prefix exists in the Trie
, false
otherwise.
Sourcepub fn search_full_world(&mut self, word: &str) -> bool
pub fn search_full_world(&mut self, word: &str) -> bool
Searches for a full word in the Trie
.
Returns true
if the exact word exists in the Trie
, false
otherwise.
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 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