pub struct Trie<K: Eq + Clone, V> { /* private fields */ }Expand description
compressed prefix tree
holds arbitrary values, uses string keys common slices of stored keys are compressed by not storing duplicates of those common slices.
Implementations§
source§impl<K: Eq + Clone, V> Trie<K, V>
impl<K: Eq + Clone, V> Trie<K, V>
sourcepub fn put(&mut self, key: &[K], val: V) -> Option<V>
pub fn put(&mut self, key: &[K], val: V) -> Option<V>
sets a key to a value returns the key evicted if there was already a key.
sourcepub fn try_put(&mut self, key: &[K], val: V) -> Result<(), KeyExistsError>
pub fn try_put(&mut self, key: &[K], val: V) -> Result<(), KeyExistsError>
sets a key to a value returns an Err() if the key already existed.
sourcepub fn remove(&mut self, key: &[K]) -> Result<V, KeyNotFoundError>
pub fn remove(&mut self, key: &[K]) -> Result<V, KeyNotFoundError>
removes a key
Ok() if key existed, Err() otherwise
source§impl<V> Trie<u8, V>
impl<V> Trie<u8, V>
sourcepub fn put_str(&mut self, key: &str, val: V) -> Option<V>
pub fn put_str(&mut self, key: &str, val: V) -> Option<V>
Puts a value in with a certain string key. The old value is ejected if it exists.
sourcepub fn try_put_str(&mut self, key: &str, val: V) -> Result<(), KeyExistsError>
pub fn try_put_str(&mut self, key: &str, val: V) -> Result<(), KeyExistsError>
Puts a value in with a certain string key. Errors if there is already a value for the given string.
sourcepub fn get_str(&mut self, key: &str) -> Option<&V>
pub fn get_str(&mut self, key: &str) -> Option<&V>
Gets a reference to the value associated to the bytes of a given string key.
sourcepub fn get_mut_str(&mut self, key: &str) -> Option<&mut V>
pub fn get_mut_str(&mut self, key: &str) -> Option<&mut V>
Gets a mutable reference to the value associated to the bytes of a given string key.
sourcepub fn has_str(&mut self, key: &str) -> bool
pub fn has_str(&mut self, key: &str) -> bool
Checks if a given string key is associated to a value.
sourcepub fn remove_str(&mut self, key: &str) -> Result<V, KeyNotFoundError>
pub fn remove_str(&mut self, key: &str) -> Result<V, KeyNotFoundError>
Removes a given string key from the Trie.