pub struct Trie<K, V>{ /* private fields */ }Expand description
A singly initialised Trie mapping sequences to a value
NOTE: It is not permitted for values to be mapped to a key that is a prefix of another key also existing in the same Try.
There are convenience methods provided for Trie<char, V> for when &str values are used as keys.
Implementations§
Source§impl<K, V> Trie<K, V>
impl<K, V> Trie<K, V>
Sourcepub fn from_pairs(pairs: Vec<(Vec<K>, V)>) -> Self
pub fn from_pairs(pairs: Vec<(Vec<K>, V)>) -> Self
Will panic if there are any key collisions or if there are any sequences that nest under a prefix that is already required to hold a value
Sourcepub fn set_default(&mut self, default: DefaultMapping<K, V>)
pub fn set_default(&mut self, default: DefaultMapping<K, V>)
Set the default handler for unmatched single element keys
Sourcepub fn get(&self, key: &[K]) -> QueryResult<V>
pub fn get(&self, key: &[K]) -> QueryResult<V>
Query this Try for a given key or key prefix.
If the key maps to a leaf then the value is returned, if it maps to a sub-trie then
Partial is returned to denote that the given key is a parent of one or more values. If
the key is not found within the Try then Missing is returned.
Sourcepub fn get_exact(&self, key: &[K]) -> Option<V>
pub fn get_exact(&self, key: &[K]) -> Option<V>
Query this Try for a given key or key prefix requiring the key to match exactly.
If the key maps to a leaf then the Some(value) is returned, otherwise None.
Sourcepub fn candidates(&self, key: &[K]) -> Vec<Vec<K>>
pub fn candidates(&self, key: &[K]) -> Vec<Vec<K>>
Find all candidate keys with the given key as a prefix (up to and including the given prefix itself).
Sourcepub fn contains_key_or_prefix(&self, key: &[K]) -> bool
pub fn contains_key_or_prefix(&self, key: &[K]) -> bool
Wether the given key is present in this Trie either as a full key or a partial prefix to multiple keys.
Source§impl<V> Trie<char, V>where
V: Clone,
impl<V> Trie<char, V>where
V: Clone,
Sourcepub fn from_str_keys(pairs: Vec<(&str, V)>) -> Self
pub fn from_str_keys(pairs: Vec<(&str, V)>) -> Self
Construct a new Trie with char internal keys from the given string keys.
Sourcepub fn get_str(&self, key: &str) -> QueryResult<V>
pub fn get_str(&self, key: &str) -> QueryResult<V>
Query this Trie using a string key.
Both full and partial matches are possible.
Sourcepub fn get_str_exact(&self, key: &str) -> Option<V>
pub fn get_str_exact(&self, key: &str) -> Option<V>
Query this Trie using a string key.
Only fll matches will be returned.
Sourcepub fn candidate_strings(&self, key: &str) -> Vec<String>
pub fn candidate_strings(&self, key: &str) -> Vec<String>
Show all partial and full matches for the given key.