Struct trees::linked::fully::tree::Tree[][src]

pub struct Tree<T> { /* fields omitted */ }

A non-nullable tree

Methods

impl<T> Tree<T>
[src]

Creates a Tree with given data on heap.

Removes and returns the given Tree's children.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
assert_eq!( tree.abandon().to_string(), "( 1 2 )" );
assert_eq!( tree, tr(0) );

Provides a forward iterator with owned data in a breadth-first manner

Examples

use trees::{bfs,Size};
use trees::linked::fully::tr;

let tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
let visits = tree.into_bfs().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    bfs::Visit{ data: 0, size: Size{ degree: 2, node_cnt: 7 }},
    bfs::Visit{ data: 1, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: 4, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: 2, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: 3, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: 5, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: 6, size: Size{ degree: 0, node_cnt: 1 }},
]);

Methods from Deref<Target = Node<T>>

Returns the number of subtrees in Forest.

Examples

use trees::linked::fully::tr;
let tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
assert_eq!( tree.degree(), 2 );

Returns the number of all subnodes in Forest.

Examples

use trees::linked::fully::tr;
let tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
assert_eq!( tree.node_count(), 7 );

Returns the first child of the forest, or None if it is empty.

Returns the given Tree's children as a borrowed Forest.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
assert_eq!( tree.forest().to_string(), "( 1 2 )" );

Returns the given Tree's children as a mutable borrowed Forest.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
for child in tree.forest_mut().iter_mut() { child.data *= 10; }
assert_eq!( tree.to_string(), "0( 10 20 )" );

Returns a mutable pointer to the first child of the forest, or None if it is empty.

Returns the last child of the forest, or None if it is empty.

Returns a mutable pointer to the last child of the forest, or None if it is empty.

Returns the parent node of this node, or None if it is a root node.

Adds the tree as the first child.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0);
tree.push_front( tr(1) );
assert_eq!( tree.to_string(), "0( 1 )" );
tree.push_front( tr(2) );
assert_eq!( tree.to_string(), "0( 2 1 )" );

Add the tree as the last child

Examples

use trees::linked::fully::tr;
let mut tree = tr(0);
tree.push_back( tr(1) );
assert_eq!( tree.to_string(), "0( 1 )" );
tree.push_back( tr(2) );
assert_eq!( tree.to_string(), "0( 1 2 )" );

Remove and return the first child

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
assert_eq!( tree.pop_front(), Some( tr(1) ));
assert_eq!( tree.to_string(), "0( 2 )" );
assert_eq!( tree.pop_front(), Some( tr(2) ));
assert_eq!( tree.to_string(), "0" );

Remove and return the last child

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
assert_eq!( tree.pop_back(), Some( tr(2) ));
assert_eq!( tree.to_string(), "0( 1 )" );
assert_eq!( tree.pop_back(), Some( tr(1) ));
assert_eq!( tree.to_string(), "0" );

Add all the forest's trees at front of children list

Examples

use trees::linked::fully::tr;
let mut tree = tr(0);
tree.prepend( -tr(1)-tr(2) );
assert_eq!( tree.to_string(), "0( 1 2 )" );
tree.prepend( -tr(3)-tr(4) );
assert_eq!( tree.to_string(), "0( 3 4 1 2 )" );

Add all the forest's trees at back of children list

Examples

use trees::linked::fully::tr;
let mut tree = tr(0);
tree.append( -tr(1)-tr(2) );
assert_eq!( tree.to_string(), "0( 1 2 )" );
tree.append( -tr(3)-tr(4) );
assert_eq!( tree.to_string(), "0( 1 2 3 4 )" );

Important traits for Iter<'a, T>

Provides a forward iterator over child Nodes

Examples

use trees::linked::fully::tr;

let tree = tr(0);
assert_eq!( tree.iter().next(), None );

let tree = tr(0) /tr(1)/tr(2);
let mut iter = tree.iter();
assert_eq!( iter.next(), Some( tr(1).root() ));
assert_eq!( iter.next(), Some( tr(2).root() ));
assert_eq!( iter.next(), None );
assert_eq!( iter.next(), None );

Important traits for Iter<'a, T>

Deprecated since 0.2.0

: please use iter instead

Important traits for IterMut<'a, T>

Provides a forward iterator over child Nodes with mutable references.

Examples

use trees::linked::fully::tr;

let mut tree = tr(0);
assert_eq!( tree.iter_mut().next(), None );

let mut tree = tr(0) /tr(1)/tr(2);
for child in tree.iter_mut() { child.data *= 10; }
assert_eq!( tree.to_string(), "0( 10 20 )" );

Important traits for IterMut<'a, T>

Deprecated since 0.2.0

: please use iter_mut instead

Important traits for OntoIter<'a, T>

Provide an iterator over Node's Subnodes for insert/remove at any position. See Subnode's document for more.

Provides a forward iterator in a breadth-first manner

Examples

use trees::{bfs,Size};
use trees::linked::fully::tr;

let tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
let visits = tree.root().bfs().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    bfs::Visit{ data: &0, size: Size{ degree: 2, node_cnt: 7 }},
    bfs::Visit{ data: &1, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: &4, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: &2, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &3, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &5, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &6, size: Size{ degree: 0, node_cnt: 1 }},
]);

Provides a forward iterator with mutable references in a breadth-first manner

Examples

use trees::{bfs,Size};
use trees::linked::fully::tr;

let mut tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
let visits = tree.root_mut().bfs_mut().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    bfs::Visit{ data: &mut 0, size: Size{ degree: 2, node_cnt: 7 }},
    bfs::Visit{ data: &mut 1, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: &mut 4, size: Size{ degree: 2, node_cnt: 3 }},
    bfs::Visit{ data: &mut 2, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &mut 3, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &mut 5, size: Size{ degree: 0, node_cnt: 1 }},
    bfs::Visit{ data: &mut 6, size: Size{ degree: 0, node_cnt: 1 }},
]);

Trait Implementations

impl<T> Split for Tree<T>
[src]

impl<T> IntoIterator for Tree<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for IntoIter<T>

Creates an iterator from a value. Read more

impl<T> Borrow<Node<T>> for Tree<T>
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<Node<T>> for Tree<T>
[src]

Mutably borrows from an owned value. Read more

impl<T> Deref for Tree<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T> DerefMut for Tree<T>
[src]

Mutably dereferences the value.

impl<T: Clone> Clone for Tree<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Drop for Tree<T>
[src]

Executes the destructor for this type. Read more

impl<T: Debug> Debug for Tree<T>
[src]

Formats the value using the given formatter. Read more

impl<T: Display> Display for Tree<T>
[src]

Formats the value using the given formatter. Read more

impl<T: PartialEq> PartialEq for Tree<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Eq> Eq for Tree<T>
[src]

impl<T: PartialOrd> PartialOrd for Tree<T>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Ord> Ord for Tree<T>
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<T: Hash> Hash for Tree<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Send> Send for Tree<T>
[src]

impl<T: Sync> Sync for Tree<T>
[src]

impl<T> FromIterator<Tree<T>> for Forest<T>
[src]

Creates a value from an iterator. Read more

impl<T> Extend<Tree<T>> for Forest<T>
[src]

Extends a collection with the contents of an iterator. Read more

impl<T> Borrow<Forest<T>> for Tree<T>
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<Forest<T>> for Tree<T>
[src]

Mutably borrows from an owned value. Read more

impl<T> Extend<Tree<T>> for Node<T>
[src]

Extends a collection with the contents of an iterator. Read more

impl<T> Neg for Tree<T>
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<'a, T: Clone> Neg for &'a Tree<T>
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<T> Sub<Self> for Tree<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T: Clone> Sub<&'a Tree<T>> for Tree<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T: Clone> Sub<Tree<T>> for &'a Tree<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T: Clone> Sub<Self> for &'a Tree<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T> Div<Forest<T>> for Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<&'a Forest<T>> for Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<Forest<T>> for &'a Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<&'a Forest<T>> for &'a Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<T> Div<Tree<T>> for Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<&'a Tree<T>> for Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<Tree<T>> for &'a Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<Self> for &'a Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<T> Div<()> for Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T: Clone> Div<()> for &'a Tree<T>
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<T> Sub<Tree<T>> for Forest<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T: Clone> Sub<&'a Tree<T>> for Forest<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T: Clone> Sub<Tree<T>> for &'a Forest<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, 'b, T: Clone> Sub<&'b Tree<T>> for &'a Forest<T>
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T> From<Tree<T>> for TreeWalk<T>
[src]

Performs the conversion.

impl<T> Into<Tree<T>> for TreeWalk<T>
[src]

Performs the conversion.