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]

[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());

[src]

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");

[src]

Returns the label of this node.

[src]

Returns the reference to the value of this node.

[src]

Returns the mutable reference to the value of this node.

[src]

Returns the reference to the child of this node.

[src]

Returns the mutable reference to the child of this node.

[src]

Returns the reference to the sibling of this node.

[src]

Returns the mutable reference to the sibling of this node.

[src]

Takes the value out of this node.

[src]

Takes the child out of this node.

[src]

Takes the sibling out of this node.

[src]

Sets the value of this node.

[src]

Sets the child of this node.

[src]

Sets the sibling of this node.

Important traits for Iter<'a, 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]

[src]

Performs the conversion.

impl<V> From<PatriciaMap<V>> for Node<V>
[src]

[src]

Performs the conversion.

impl<V> AsRef<Node<V>> for PatriciaMap<V>
[src]

[src]

Performs the conversion.

impl<V: Debug> Debug for Node<V>
[src]

[src]

Formats the value using the given formatter. Read more

impl<V> Send for Node<V>
[src]

impl<V> Drop for Node<V>
[src]

[src]

Executes the destructor for this type. Read more

impl<V: Clone> Clone for Node<V>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<V> IntoIterator for Node<V>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl From<Node<()>> for PatriciaSet
[src]

[src]

Performs the conversion.

impl From<PatriciaSet> for Node<()>
[src]

[src]

Performs the conversion.

impl AsRef<Node<()>> for PatriciaSet
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<V> !Sync for Node<V>