Struct Trie

Source
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

Source

pub fn new() -> Self

Creates a new, empty Trie with a root node.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for Trie

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.