Skip to main content

Node

Struct Node 

Source
pub struct Node<T, C = DefaultStorage>
where C: Storage + ?Sized,
{ pub prefixes: Array256<Vec<T>>, pub children: Array256<Vec<Child<C::Container<Self>, T>>>, }
Expand description

A trie node logically covering a single (octet) address stride.

Contains prefixes (directly owned by this node) and children (descendants in the trie).

This is the canonical stride-level Node type for the crate, mirroring go-bart’s Full nodes. The operations its supports are abstracted for via the StrideOps trait – other implementations are possible, e.g. to support similar functionality to go-bart’s Lite and Fast node types.

Fields§

§prefixes: Array256<Vec<T>>

The prefixes this node covers directly, indexed by BaseIndex.

If this node is at trie depth 3 via octet path [192, 168] for instance, the prefix entry 12/5 => 34 would represent the overall trie route mapping 192.168.12.0/21 => 34.

§children: Array256<Vec<Child<C::Container<Self>, T>>>

The children contained in this node, indexed by complete prefix octet.

Implementations§

Source§

impl<T, C> Node<T, C>
where C: Storage + ?Sized,

Source

pub fn descendants( &self, include_self: bool, ) -> impl Iterator<Item = (Vec<u8, 16>, Child<&Self, &T>)>

Get all the descendant Children of this node. Order is depth-first, in-order by address.

Source

pub fn descendant_nodes( &self, include_self: bool, ) -> impl Iterator<Item = (Vec<u8, 16>, &Self)>

Get all the descendant Nodes of this node. Order is depth-first, in-order by address.

Source§

impl<T, C> Node<T, C>
where C: Storage + ?Sized,

Source

pub const EMPTY: Self

The empty node value (no children, no prefixes).

Source

pub const fn is_empty(&self) -> bool

Returns whether the node is empty.

Source

pub fn stats(&self) -> Stats
where Self: StrideOps,

Return usage statistics for the trie rooted at this node.

Trait Implementations§

Source§

impl<T, C> Clone for Node<T, C>
where C: Storage + ?Sized, T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, C> Debug for Node<T, C>
where T: Debug, C: Storage + ?Sized,

Source§

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

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

impl<T, C> Default for Node<T, C>
where C: Storage + ?Sized,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Eq, C> Eq for Node<T, C>
where C: Storage + ?Sized + Eq, C::Container<Self>: Eq,

Source§

impl<T: Hash, C> Hash for Node<T, C>
where C: Storage + ?Sized + Hash, C::Container<Self>: Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq, C> PartialEq for Node<T, C>
where C: Storage + ?Sized + PartialEq, C::Container<Self>: PartialEq,

Source§

fn eq(&self, other: &Node<T, C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T, C> PrefixOps for Node<T, C>
where T: 'static, C: Storage + ?Sized,

Source§

fn insert_prefix(&mut self, idx: BaseIndex, value: Self::T) -> Option<Self::T>

Insert a value at the given base index.
Source§

fn remove_prefix(&mut self, idx: BaseIndex) -> Option<Self::T>

Remove the value for the given base index.
Source§

fn get_prefix_exact_mut(&mut self, idx: BaseIndex) -> Option<&mut Self::T>

Get a mutable reference to the prefix value that matches the given index exactly.
Source§

impl<T, C> PrefixReadOps for Node<T, C>
where T: 'static, C: Storage + ?Sized,

Source§

fn prefix_bitset(&self) -> &Bitset256

Get a reference to the prefix bitset.
Source§

fn prefix_count(&self) -> usize

Get the number of prefixes in this node.
Source§

fn lookup_index(&self, idx: BaseIndex) -> Option<(BaseIndex, &Self::T)>

Lookup the prefix value that covers the given index.
Source§

fn get_prefix_exact(&self, idx: BaseIndex) -> Option<&Self::T>

Get a reference to the prefix value that matches the given index exactly.
Source§

impl<T, C> StrideBase for Node<T, C>
where T: 'static, C: Storage + ?Sized,

Source§

type T = T

The kind of value held inside nodes.
Source§

impl<T, C> StrideOps for Node<T, C>
where T: 'static, C: Storage + ?Sized,

Source§

fn child_bitset(&self) -> &Bitset256

Get a reference to the child bitset.
Source§

fn child_count(&self) -> usize

Get the number of direct children of this node.
Source§

fn stats(&self) -> Stats

Calculate trie occupancy stats for this node and its descendants.
Source§

fn insert_child( &mut self, addr: u8, child: Child<Self, Self::T>, ) -> Option<Child<Self, Self::T>>

Insert a child node at the given address.
Source§

fn direct_children(&self) -> impl Iterator<Item = (u8, Child<&Self, &T>)>

Iterate the direct children of this node.
Source§

fn remove_child(&mut self, addr: u8) -> Option<Child<Self, Self::T>>

Remove a child node at the given address.
Source§

fn get_child(&self, addr: u8) -> Option<Child<&Self, &Self::T>>

Get a child node by address.
Source§

fn get_child_mut(&mut self, addr: u8) -> Option<Child<&mut Self, &mut Self::T>>

Get a mutable reference to a child node by address.
Source§

fn direct_prefixes(&self) -> impl Iterator<Item = (BaseIndex, &T)>

Iterate the prefixes directly contained in this node.
Source§

impl<T, C> StructuralPartialEq for Node<T, C>
where C: Storage + ?Sized,

Auto Trait Implementations§

§

impl<T, C> Freeze for Node<T, C>
where C: ?Sized,

§

impl<T, C> RefUnwindSafe for Node<T, C>
where T: RefUnwindSafe, <C as Storage>::Container<Node<T, C>>: RefUnwindSafe, C: ?Sized,

§

impl<T, C> Send for Node<T, C>
where T: Send, <C as Storage>::Container<Node<T, C>>: Send, C: ?Sized,

§

impl<T, C> Sync for Node<T, C>
where T: Sync, <C as Storage>::Container<Node<T, C>>: Sync, C: ?Sized,

§

impl<T, C> Unpin for Node<T, C>
where T: Unpin, <C as Storage>::Container<Node<T, C>>: Unpin, C: ?Sized,

§

impl<T, C> UnsafeUnpin for Node<T, C>
where C: ?Sized,

§

impl<T, C> UnwindSafe for Node<T, C>
where T: UnwindSafe, <C as Storage>::Container<Node<T, C>>: UnwindSafe, C: ?Sized,

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> PrefixOpsExt for T
where T: PrefixOps + ?Sized,

Source§

fn supersets_prefix(&self, idx: BaseIndex) -> bool

Report whether this node’s prefix set covers the prefix with the given index. It does not need to match exactly, idx just needs to be contained in this node’s prefix set. Read more
Source§

fn lookup(&self, idx: BaseIndex) -> Option<&Self::T>

Lookup a value by BaseIndex. Read more
Source§

fn with_prefix(self, idx: BaseIndex, value: Self::T) -> Self
where Self: Sized,

Return this node with the given prefix added. Read more
Source§

fn matching_prefixes(&self, octet: u8) -> NodePrefixIter<'_, Self::T>
where Self: Sized,

Iterate prefixes in this node matching octet. Read more
Source§

impl<T> StrideOpsExt for T
where T: StrideOps,

Source§

fn is_empty(&self) -> bool

Report whether the node has no children and prefixes.
Source§

fn with_child(self, addr: u8, child: impl Into<Child<Self, Self::T>>) -> Self

Return this node with the given child added. Read more
Source§

fn into_child(self) -> Child<Self, Self::T>

Wrap this node in a Child::Path.
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.