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>
impl<V> Node<V>
Sourcepub fn take_children(&mut self) -> Option<Vec<Node<V>>>
pub fn take_children(&mut self) -> Option<Vec<Node<V>>>
take all the children out of a node and return them
Sourcepub fn children_len(&self) -> usize
pub fn children_len(&self) -> usize
return number of children
Sourcepub fn iter(&self) -> Iter<'_, V>
pub fn iter(&self) -> Iter<'_, V>
Gets an iterator which traverses the nodes in this tree, in depth first order.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, V>
pub fn iter_mut(&mut self) -> IterMut<'_, V>
Gets a mutable iterator which traverses the nodes in this tree, in depth first order.
Sourcepub fn iter_bfs(&self) -> IterBfs<'_, V>
pub fn iter_bfs(&self) -> IterBfs<'_, V>
Gets an iterator which traverses the nodes in this tree, in breadth first order.
Sourcepub fn iter_mut_bfs(&mut self) -> IterMutBfs<'_, V>
pub fn iter_mut_bfs(&mut self) -> IterMutBfs<'_, V>
Gets a mutable iterator which traverses the nodes in this tree, in breadth first order.
Sourcepub fn split_by_prefix<K: ?Sized + BorrowedBytes>(
&mut self,
key: &K,
) -> Option<Self>
pub fn split_by_prefix<K: ?Sized + BorrowedBytes>( &mut self, key: &K, ) -> Option<Self>
split the node by the prefix into two distinct nodes
Sourcepub fn remove<K: ?Sized + BorrowedBytes>(&mut self, key: &K) -> Option<V>
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.
Sourcepub fn try_merge_child(&mut self)
pub fn try_merge_child(&mut self)
merge child if we only have one child
Sourcepub fn entry<K>(&mut self, key: &K) -> Entry<'_, V>where
K: ?Sized + BorrowedBytes,
pub fn entry<K>(&mut self, key: &K) -> Entry<'_, V>where
K: ?Sized + BorrowedBytes,
entry api for node
Sourcepub fn insert<K: ?Sized + BorrowedBytes>(
&mut self,
key: &K,
value: V,
) -> Option<V>
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
Sourcepub fn into_iter_bfs(self) -> IntoIterBfs<V>
pub fn into_iter_bfs(self) -> IntoIterBfs<V>
construct into_iter iterates breadth first search style
Source§impl<V> Node<V>
impl<V> Node<V>
Sourcepub fn new<const N: usize>(
label: &[u8],
children: [Node<V>; N],
value: Option<V>,
) -> Self
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
Sourcepub fn value_mut(&mut self) -> Option<&mut V>
pub fn value_mut(&mut self) -> Option<&mut V>
Returns the mutable reference to the value of this node.
Sourcepub fn as_mut(&mut self) -> NodeMut<'_, V>
pub fn as_mut(&mut self) -> NodeMut<'_, V>
Returns mutable references to the node itself with its sibling and child
Sourcepub fn take_value(&mut self) -> Option<V>
pub fn take_value(&mut self) -> Option<V>
Takes the value out of this node.
Sourcepub fn prefix_label(&mut self, prefix: &[u8])
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
Sourcepub fn replace_label(&mut self, prefix: &[u8])
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