Node

Struct Node 

Source
pub struct Node<V> { /* private fields */ }
Expand description

A node which represents a subtree of a patricia tree.

Note that this is a low level building block. Usually it is recommended to use more high level data structures (e.g., PatriciaTree).

Implementations§

Source§

impl<V> Node<V>

Source

pub fn root() -> Self

Makes a new node which represents an empty tree.

Source

pub fn label(&self) -> &[u8]

Returns the label of this node.

Source

pub fn children(&self) -> &[Node<V>]

get all children for node as slice

Source

pub fn take_children(&mut self) -> Option<Vec<Node<V>>>

take all the children out of a node and return them

Source

pub fn children_len(&self) -> usize

return number of children

Source

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

Gets an iterator which traverses the nodes in this tree, in depth first order.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, V>

Gets a mutable iterator which traverses the nodes in this tree, in depth first order.

Source

pub fn iter_bfs(&self) -> IterBfs<'_, V>

Gets an iterator which traverses the nodes in this tree, in breadth first order.

Source

pub fn iter_mut_bfs(&mut self) -> IterMutBfs<'_, V>

Gets a mutable iterator which traverses the nodes in this tree, in breadth first order.

Source

pub fn split_by_prefix<K: ?Sized + BorrowedBytes>( &mut self, key: &K, ) -> Option<Self>

split the node by the prefix into two distinct nodes

Source

pub fn remove<K: ?Sized + BorrowedBytes>(&mut self, key: &K) -> Option<V>

remove the value at key and return it, merging the tree with its children if necessary.

Source

pub fn try_merge_child(&mut self)

merge child if we only have one child

Source

pub fn entry<K>(&mut self, key: &K) -> Entry<'_, V>
where K: ?Sized + BorrowedBytes,

entry api for node

Source

pub fn insert<K: ?Sized + BorrowedBytes>( &mut self, key: &K, value: V, ) -> Option<V>

insert key and value into node, replacing value if key exists could be re-written to use Entry but the non-entry version is 5-10% faster so I’m leaving this for now SAFETY: caller must not insert an empty label into children. only the root node can have an empty label

Source

pub fn label_len(&self) -> usize

return node label length

Source

pub fn into_iter_bfs(self) -> IntoIterBfs<V>

construct into_iter iterates breadth first search style

Source§

impl<V> Node<V>

Source

pub fn new<const N: usize>( label: &[u8], children: [Node<V>; N], value: Option<V>, ) -> Self

Makes a new node. SAFETY: - label len must not exceed 255 - children len must not exceed 255

Source

pub fn value(&self) -> Option<&V>

Returns the reference to the value of this node.

Source

pub fn value_mut(&mut self) -> Option<&mut V>

Returns the mutable reference to the value of this node.

Source

pub fn as_mut(&mut self) -> NodeMut<'_, V>

Returns mutable references to the node itself with its sibling and child

Source

pub fn take_value(&mut self) -> Option<V>

Takes the value out of this node.

Source

pub fn prefix_label(&mut self, prefix: &[u8])

set label with prefix slice NOTE: you can seriously mess up a node calling these functions manually

Source

pub fn replace_label(&mut self, prefix: &[u8])

swap label with new one (will realloc node) NOTE: you can seriously mess up a node calling these functions manually

Source

pub fn set_value(&mut self, value: V)

Sets the value of this node.

Trait Implementations§

Source§

impl<V: Clone> Clone for Node<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Node<V>

Source§

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

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

impl<V> Drop for Node<V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<V> IntoIterator for Node<V>

Source§

type Item = (usize, Node<V>)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<V: PartialEq> PartialEq for Node<V>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Eq> Eq for Node<V>

Source§

impl<V: Send> Send for Node<V>

Source§

impl<V: Sync> Sync for Node<V>

Auto Trait Implementations§

§

impl<V> Freeze for Node<V>

§

impl<V> RefUnwindSafe for Node<V>
where V: RefUnwindSafe,

§

impl<V> Unpin for Node<V>
where V: Unpin,

§

impl<V> UnwindSafe for Node<V>
where 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.