pub struct Trie<Label, Value> { /* private fields */ }
Expand description
A trie for sequences of the type Label
; each sequence has an associated Value
.
Implementations§
source§impl<Label: Ord, Value> Trie<Label, Value>
impl<Label: Ord, Value> Trie<Label, Value>
sourcepub fn exact_match(&self, query: impl AsRef<[Label]>) -> Option<&Value>
pub fn exact_match(&self, query: impl AsRef<[Label]>) -> Option<&Value>
Return Some(&Value)
if query is an exact match.
sourcepub fn exact_match_mut(
&mut self,
query: impl AsRef<[Label]>
) -> Option<&mut Value>
pub fn exact_match_mut( &mut self, query: impl AsRef<[Label]> ) -> Option<&mut Value>
Return Some(&mut value)
if query is an exact match.
sourcepub fn inc_search(&self) -> IncSearch<'_, Label, Value>
pub fn inc_search(&self) -> IncSearch<'_, Label, Value>
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 predictive_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> SearchIter<'_, Label, Value, C, M> ⓘ
pub fn predictive_search<C, M>( &self, query: impl AsRef<[Label]> ) -> SearchIter<'_, Label, Value, C, M> ⓘ
Return all entries and their values that match query
.
sourcepub fn postfix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> PostfixIter<'_, Label, Value, C, M> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn postfix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> PostfixIter<'_, Label, Value, C, M> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
Return the postfixes and values of all entries that match query
.
sourcepub fn iter<C, M>(&self) -> PostfixIter<'_, Label, Value, C, M> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn iter<C, M>(&self) -> PostfixIter<'_, Label, Value, 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::map::Trie;
let trie = Trie::from_iter([("a", 0), ("app", 1), ("apple", 2), ("better", 3), ("application", 4)]);
let results: Vec<(String, &u8)> = trie.iter().collect();
assert_eq!(results, [("a".to_string(), &0u8), ("app".to_string(), &1u8), ("apple".to_string(), &2u8), ("application".to_string(), &4u8), ("better".to_string(), &3u8)]);
sourcepub fn common_prefix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> PrefixIter<'_, Label, Value, C, M> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
pub fn common_prefix_search<C, M>(
&self,
query: impl AsRef<[Label]>
) -> PrefixIter<'_, Label, Value, C, M> ⓘwhere
C: TryFromIterator<Label, M>,
Label: Clone,
Return the common prefixes of query
.
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 or terminal of query
.
Trait Implementations§
source§impl<Label, Value, C> FromIterator<(C, Value)> for Trie<Label, Value>
impl<Label, Value, C> FromIterator<(C, Value)> for Trie<Label, Value>
Auto Trait Implementations§
impl<Label, Value> Freeze for Trie<Label, Value>
impl<Label, Value> RefUnwindSafe for Trie<Label, Value>where
Label: RefUnwindSafe,
Value: RefUnwindSafe,
impl<Label, Value> Send for Trie<Label, Value>
impl<Label, Value> Sync for Trie<Label, Value>
impl<Label, Value> Unpin for Trie<Label, Value>
impl<Label, Value> UnwindSafe for Trie<Label, Value>where
Label: UnwindSafe,
Value: 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