Skip to main content

Trie

Struct Trie 

Source
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

Source

pub fn new() -> Self

Source

pub fn node_count(&self) -> usize

Total number of nodes (including root).

Source

pub fn word_count(&self) -> usize

Number of distinct words stored.

Source

pub fn contains(&self, word: &str) -> bool

Returns true if word exists in the trie.

Source

pub fn contains_prefix(&self, prefix: &str) -> bool

Returns true if prefix is a prefix of any word in the trie.

Source

pub fn add(&mut self, word: &str, count: usize) -> Result<(), LexError>

Add a word with an optional count (default 1).

Source

pub fn add_all<I: IntoIterator<Item = String>>( &mut self, words: I, ) -> Result<(), LexError>

Add all words from an iterator.

Source

pub fn add_from_file(&mut self, path: &str) -> Result<(), LexError>

Add all words from a file (one word per line).

Source

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.

Source

pub fn search_with_count( &self, pattern: &str, ) -> Result<Vec<(String, usize)>, LexError>

Like search but also returns word counts.

Source

pub fn search_with_prefix(&self, prefix: &str) -> Vec<String>

Return all words with the given prefix.

Source

pub fn search_with_prefix_count(&self, prefix: &str) -> Vec<(String, usize)>

Like search_with_prefix but also returns counts.

Source

pub fn search_within_distance(&self, word: &str, dist: usize) -> Vec<String>

Return all words within Levenshtein dist of word.

Source

pub fn search_within_distance_count( &self, word: &str, dist: usize, ) -> Vec<(String, usize)>

Like search_within_distance but also returns counts.

Trait Implementations§

Source§

impl Default for Trie

Source§

fn default() -> Self

Returns the “default value” for a type. 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 UnsafeUnpin 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.