[−][src]Struct patricia_tree::node::Node
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> Send for Node<V>
[src]
impl<V> Drop for Node<V>
[src]
impl<V> AsRef<Node<V>> for PatriciaMap<V>
[src]
impl AsRef<Node<()>> for PatriciaSet
[src]
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]
impl From<Node<()>> for PatriciaSet
[src]
impl From<PatriciaSet> for Node<()>
[src]
fn from(f: PatriciaSet) -> Self
[src]
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]
impl<V: Clone> Clone for Node<V>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<V: Debug> Debug for Node<V>
[src]
Auto Trait Implementations
impl<V> !Sync for Node<V>
impl<V> Unpin for Node<V> where
V: Unpin,
V: Unpin,
impl<V> UnwindSafe for Node<V> where
V: UnwindSafe,
V: UnwindSafe,
impl<V> RefUnwindSafe for Node<V> where
V: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,