Struct PatriciaTree

Source
pub struct PatriciaTree<K: Copy, V> { /* private fields */ }
Expand description

Patricia troo

Implementations§

Source§

impl<K, V> PatriciaTree<K, V>
where K: Copy + BitArray + Eq + BitXor<K, Output = K> + Add<K, Output = K> + Shr<usize, Output = K> + Shl<usize, Output = K>,

Source

pub fn new() -> PatriciaTree<K, V>

Constructs a new Patricia tree

Source

pub fn lookup_mut(&mut self, key: &K, key_len: usize) -> Option<&mut V>

Lookup a value by exactly matching key and return a referenc

Source

pub fn lookup(&self, key: &K, key_len: usize) -> Option<&V>

Lookup a value by exactly matching key and return a mutable reference

Source

pub fn insert(&mut self, key: &K, key_len: usize, value: V) -> bool

Inserts a value with key key, returning true on success. If a value is already stored against key, do nothing and return false.

Source

pub fn insert_or_update(&mut self, key: &K, key_len: usize, value: V) -> bool

Inserts a value with key key, returning true on success. If a value is already stored against key, overwrite it and return false.

Source

pub fn delete(&mut self, key: &K, key_len: usize) -> Option<V>

Deletes a value with key key, returning it on success. If no value with the given key is found, return None

Source

pub fn node_count(&self) -> usize

Count all the nodes

Source

pub fn iter(&self) -> Items<'_, K, V>

Returns an iterator over all elements in the tree

Source

pub fn mut_iter(&mut self) -> MutItems<'_, K, V>

Returns a mutable iterator over all elements in the tree

Trait Implementations§

Source§

impl<K: Copy + BitArray, V: Debug> Debug for PatriciaTree<K, V>

Source§

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

Print the entire tree

Source§

impl<D, K, V> Decodable<D> for PatriciaTree<K, V>
where D: Decoder, K: Copy + Decodable<D>, V: Decodable<D>,

Source§

fn consensus_decode(d: &mut D) -> Result<PatriciaTree<K, V>, Error>

Decode an object with a well-defined format
Source§

impl<S, K, V> Encodable<S> for PatriciaTree<K, V>
where S: Encoder, K: Copy + Encodable<S>, V: Encodable<S>,

Source§

fn consensus_encode(&self, s: &mut S) -> Result<(), Error>

Encode an object with a well-defined format, should only ever error if the underlying Encoder errors.

Auto Trait Implementations§

§

impl<K, V> Freeze for PatriciaTree<K, V>
where K: Freeze, V: Freeze,

§

impl<K, V> RefUnwindSafe for PatriciaTree<K, V>

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Source§

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.