pub struct Trie<Label>(pub Trie<Label, ()>);
Expand description
A trie for sequences of the type Label
.
Tuple Fields§
§0: Trie<Label, ()>
Implementations§
source§impl<Label: Ord> Trie<Label>
impl<Label: Ord> Trie<Label>
sourcepub fn exact_match(&self, query: impl AsRef<[Label]>) -> bool
pub fn exact_match(&self, query: impl AsRef<[Label]>) -> bool
Return true if query
is an exact match.
§Arguments
query
- The query to search for.
§Examples
In the following example we illustrate how to query an exact match.
use trie_rs::Trie;
let trie = Trie::from_iter(["a", "app", "apple", "better", "application"]);
assert!(trie.exact_match("application"));
assert!(trie.exact_match("app"));
assert!(!trie.exact_match("appla"));
sourcepub fn common_prefix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> Keys<PrefixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn common_prefix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> Keys<PrefixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
Return the common prefixes of query
.
§Arguments
query
- The query to search for.
§Examples
In the following example we illustrate how to query the common prefixes of a query string.
use trie_rs::Trie;
let trie = Trie::from_iter(["a", "app", "apple", "better", "application"]);
let results: Vec<String> = trie.common_prefix_search("application").collect();
assert_eq!(results, vec!["a", "app", "application"]);
sourcepub fn predictive_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> Keys<SearchIter<'_, Label, (), C, M>> ⓘ
pub fn predictive_search<C, M>( &self, query: impl AsRef<[Label]> ) -> Keys<SearchIter<'_, Label, (), C, M>> ⓘ
Return all entries that match query
.
sourcepub fn postfix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> Keys<PostfixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn postfix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> Keys<PostfixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
Return the postfixes of all entries that match query
.
§Arguments
query
- The query to search for.
§Examples
In the following example we illustrate how to query the postfixes of a query string.
use trie_rs::Trie;
let trie = Trie::from_iter(["a", "app", "apple", "better", "application"]);
let results: Vec<String> = trie.postfix_search("application").collect();
assert!(results.is_empty());
let results: Vec<String> = trie.postfix_search("app").collect();
assert_eq!(results, vec!["le", "lication"]);
sourcepub fn iter<C, M>(&self) -> Keys<PostfixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn iter<C, M>(&self) -> Keys<PostfixIter<'_, Label, (), C, M>> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
Returns an iterator across all keys in the trie.
§Examples
In the following example we illustrate how to iterate over all keys in the trie. Note that the order of the keys is not guaranteed, as they will be returned in lexicographical order.
use trie_rs::Trie;
let trie = Trie::from_iter(["a", "app", "apple", "better", "application"]);
let results: Vec<String> = trie.iter().collect();
assert_eq!(results, vec!["a", "app", "apple", "application", "better"]);
sourcepub fn inc_search(&self) -> IncSearch<'_, Label, ()>
pub fn inc_search(&self) -> IncSearch<'_, Label, ()>
Create an incremental search. Useful for interactive applications. See crate::inc_search for details.
sourcepub fn is_prefix(&self, query: impl AsRef<[Label]>) -> bool
pub fn is_prefix(&self, query: impl AsRef<[Label]>) -> bool
Return true if query
is a prefix.
Note: A prefix may be an exact match or not, and an exact match may be a prefix or not.
sourcepub fn longest_prefix<C, M>(&self, query: impl AsRef<[Label]>) -> Option<C>where
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn longest_prefix<C, M>(&self, query: impl AsRef<[Label]>) -> Option<C>where
C: TryFromIterator<Label, M>,
Label: Clone,
Return the longest shared prefix of query
.
Trait Implementations§
Auto Trait Implementations§
impl<Label> Freeze for Trie<Label>
impl<Label> RefUnwindSafe for Trie<Label>where
Label: RefUnwindSafe,
impl<Label> Send for Trie<Label>where
Label: Send,
impl<Label> Sync for Trie<Label>where
Label: Sync,
impl<Label> Unpin for Trie<Label>where
Label: Unpin,
impl<Label> UnwindSafe for Trie<Label>where
Label: UnwindSafe,
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more