Struct patricia_tree::node::Node
[−]
[src]
pub struct Node<V> { /* fields omitted */ }
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
).
Methods
impl<V> Node<V>
[src]
pub fn root() -> Self
[src]
Makes a new node which represents an empty tree.
Examples
use patricia_tree::node::Node; let node = Node::<()>::root(); assert!(node.label().is_empty()); assert!(node.value().is_none()); assert!(node.child().is_none()); assert!(node.sibling().is_none());
pub fn new(
label: &[u8],
value: Option<V>,
child: Option<Self>,
sibling: Option<Self>
) -> Self
[src]
label: &[u8],
value: Option<V>,
child: Option<Self>,
sibling: Option<Self>
) -> Self
Makes a new node.
Examples
use patricia_tree::node::Node; let node0 = Node::new("foo".as_ref(), Some(3), None, None); assert_eq!(node0.label(), b"foo"); assert_eq!(node0.value(), Some(&3)); assert_eq!(node0.child().map(|n| n.label()), None); assert_eq!(node0.sibling().map(|n| n.label()), None); let node1 = Node::new("bar".as_ref(), None, None, Some(node0)); assert_eq!(node1.label(), b"bar"); assert_eq!(node1.value(), None); assert_eq!(node1.child().map(|n| n.label()), None); assert_eq!(node1.sibling().map(|n| n.label()), Some(&b"foo"[..])); // If the length of a label name is longer than 255, it will be splitted to two nodes. let node2 = Node::new([b'a'; 256].as_ref(), Some(4), Some(node1), None); assert_eq!(node2.label(), [b'a'; 255].as_ref()); assert_eq!(node2.value(), None); assert_eq!(node2.child().map(|n| n.label()), Some(&b"a"[..])); assert_eq!(node2.sibling().map(|n| n.label()), None); assert_eq!(node2.child().unwrap().value(), Some(&4)); assert_eq!(node2.child().unwrap().child().unwrap().label(), b"bar");
pub fn label(&self) -> &[u8]
[src]
Returns the label of this node.
pub fn value(&self) -> Option<&V>
[src]
Returns the reference to the value of this node.
pub fn value_mut(&mut self) -> Option<&mut V>
[src]
Returns the mutable reference to the value of this node.
pub fn child(&self) -> Option<&Self>
[src]
Returns the reference to the child of this node.
pub fn child_mut(&mut self) -> Option<&mut Self>
[src]
Returns the mutable reference to the child of this node.
pub fn sibling(&self) -> Option<&Self>
[src]
Returns the reference to the sibling of this node.
pub fn sibling_mut(&mut self) -> Option<&mut Self>
[src]
Returns the mutable reference to the sibling of this node.
pub fn take_value(&mut self) -> Option<V>
[src]
Takes the value out of this node.
pub fn take_child(&mut self) -> Option<Self>
[src]
Takes the child out of this node.
pub fn take_sibling(&mut self) -> Option<Self>
[src]
Takes the sibling out of this node.
pub fn set_value(&mut self, value: V)
[src]
Sets the value of this node.
pub fn set_child(&mut self, child: Self)
[src]
Sets the child of this node.
pub fn set_sibling(&mut self, sibling: Self)
[src]
Sets the sibling of this node.
ⓘImportant traits for Iter<'a, V>pub fn iter(&self) -> Iter<V>
[src]
Gets an iterator which traverses the nodes in this tree, in depth first order.
Examples
use patricia_tree::PatriciaSet; use patricia_tree::node::Node; let mut set = PatriciaSet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); let node = Node::from(set); let nodes = node.iter().map(|(level, node)| (level, node.label())).collect::<Vec<_>>(); assert_eq!(nodes, [ (0, "".as_ref()), (1, "ba".as_ref()), (2, "r".as_ref()), (2, "z".as_ref()), (1, "foo".as_ref()) ]);
Trait Implementations
impl<V> From<Node<V>> for PatriciaMap<V>
[src]
impl<V> From<PatriciaMap<V>> for Node<V>
[src]
fn from(f: PatriciaMap<V>) -> Self
[src]
Performs the conversion.
impl<V> AsRef<Node<V>> for PatriciaMap<V>
[src]
impl<V: Debug> Debug for Node<V>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<V> Send for Node<V>
[src]
impl<V> Drop for Node<V>
[src]
impl<V: Clone> Clone for Node<V>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<V> IntoIterator for Node<V>
[src]
type Item = (usize, Node<V>)
The type of the elements being iterated over.
type IntoIter = IntoIter<V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl From<Node<()>> for PatriciaSet
[src]
impl From<PatriciaSet> for Node<()>
[src]
fn from(f: PatriciaSet) -> Self
[src]
Performs the conversion.