Struct v_trie::Trie

source ·
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>

source

pub fn new() -> Self

constructs an empty prefix tree

source

pub fn get_mut(&mut self, key: &[K]) -> Option<&mut V>

gets the value of a key as mutable

source

pub fn has(&self, key: &[K]) -> bool

checks if a key exists

source

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.

source

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.

source

pub fn remove(&mut self, key: &[K]) -> Result<V, KeyNotFoundError>

removes a key

Ok() if key existed, Err() otherwise

source

pub fn size(&self) -> usize

Gets the size of the tree in terms of nodes.

source§

impl<V> Trie<u8, V>

source

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.

source

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.

source

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.

source

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.

source

pub fn has_str(&mut self, key: &str) -> bool

Checks if a given string key is associated to a value.

source

pub fn remove_str(&mut self, key: &str) -> Result<V, KeyNotFoundError>

Removes a given string key from the Trie.

Trait Implementations§

source§

impl<K: Debug + Eq + Clone, V: Debug> Debug for Trie<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: PartialEq + Eq + Clone, V: PartialEq> PartialEq<Trie<K, V>> for Trie<K, V>

source§

fn eq(&self, other: &Trie<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: Eq + Eq + Clone, V: Eq> Eq for Trie<K, V>

source§

impl<K: Eq + Clone, V> StructuralEq for Trie<K, V>

source§

impl<K: Eq + Clone, V> StructuralPartialEq for Trie<K, V>

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for Trie<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for Trie<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for Trie<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for Trie<K, V>where V: Unpin,

§

impl<K, V> UnwindSafe for Trie<K, V>where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.