Struct trees::Tree [] [src]

pub struct Tree<T>(_);

Tree with owned Nodes.

Methods

impl<T> Tree<T>
[src]

[src]

Creates a Tree with given data on heap. Tree is NOT nullable. Consider using an empty Forest instead if needed.

Examples

use trees::Tree;

let tree = Tree::new( 1 );
assert_eq!( tree.data, 1 );

[src]

Append the given trees at the end of the Tree's children list.

Examples

use trees::tr;

let mut tree = tr(0);
tree = tree.adopt( -tr(1)-tr(2) );
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next(), None );

[src]

Prepend the given tree at the begin of the Tree's children list.

Examples

use trees::{tr,fr};

let mut tree = tr(0);
tree = tree.prepend( tr(1) );
tree = tree.prepend( tr(2) );
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next(), None );

[src]

Prepend the given tree at the begin of the Tree's children list.

Examples

use trees::{tr,fr};

let mut tree = tr(0);
tree = tree.append( tr(1) );
tree = tree.append( tr(2) );
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next(), None );

Methods from Deref<Target = Node<T>>

[src]

Append the given trees at the end of the Node's children list.

[src]

Removes and returns the given tree Node's children.

Examples

use trees::tr;

let mut tree = tr(0) /tr(1)/tr(2);
let children = tree.abandon();
assert_eq!( tree, tr(0) );
assert_eq!( children, -tr(1)-tr(2) );

[src]

Adds the child as the first child.

Examples

use trees::tr;

let mut tree = tr(0) /tr(1);
tree.push_front( tr(2) );
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next(), None );

[src]

remove and return the first child

Examples

use trees::tr;

let mut tree = tr(0) /tr(1)/tr(2);
let child = tree.pop_front();
assert_eq!( tree, tr(0) /tr(2) );
assert_eq!( child.unwrap(), tr(1) );

[src]

add the child as the last child

Examples

use trees::tr;

let mut tree = tr(0) /tr(1);
tree.push_back( tr(2) );
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next(), None );

Important traits for Iter<'a, T>
[src]

Provides a forward iterator over tree Node's direct decendants

Examples

use trees::tr;

let tree = tr(0)
    /( tr(1) /tr(2)/tr(3) )
    /( tr(4) /tr(5)/tr(6) )
;
let mut iter = tree.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(1) /tr(2)/tr(3) );
assert_eq!( iter.next().unwrap().to_owned(), tr(4) /tr(5)/tr(6) );
assert_eq!( iter.next(), None );

Important traits for IterMut<'a, T>
[src]

Provides a forward iterator over tree Node's direct decendants with mutable references.

Examples

use trees::tr;

let mut tree = tr(0)
    /( tr(1) /tr(2)/tr(3) )
    /( tr(4) /tr(5)/tr(6) )
;
for mut child in tree.children_mut() {
    child.data *= 10;
}
let expedted = tr(0)
    /( tr(10) /tr(2)/tr(3) )
    /( tr(40) /tr(5)/tr(6) )
;
assert_eq!( tree, expedted );

Important traits for SubtreeIter<T>
[src]

Provide an iterator over the tree Node's subtrees for insert/remove at any position

Examples

insert after

use trees::tr;

let mut tree = tr(0) /tr(1)/tr(2)/tr(3);
for mut sub in tree.subtrees() {
    sub.insert_sib( tr(3) );
}
assert_eq!( tree, tr(0) /tr(1)/tr(3)/tr(2)/tr(3)/tr(3)/tr(3) );

insert before

use trees::tr;

let mut tree = tr(0) /tr(1)/tr(3)/tr(4);
let mut iter = tree.subtrees().peekable();
while let Some(mut sub) = iter.next() { 
    if let Some(next_sub) = iter.peek() {
        if next_sub.data == 3 {
            sub.insert_sib( tr(2) );
        }
    }
}
assert_eq!( tree, tr(0) /tr(1)/tr(2)/tr(3)/tr(4) );

remove

use trees::tr;
let mut tree = tr(0) /tr(1)/tr(2)/tr(3)/tr(4)/tr(5)/tr(6);
for mut sub in tree.subtrees() {
    let d = sub.data;
    if d%2 == 0 || d%3 == 0 {
        sub.remove();
    }
}
assert_eq!( tree, tr(0) /tr(1)/tr(5) );

[src]

Returns true if the Node has no children.

This operation should compute in O(1) time.

Examples

use trees::{tr};

let mut tree = tr(0);
assert!( tree.is_leaf() );
tree.push_back( tr(1) ); 
assert!( !tree.is_leaf() );

Trait Implementations

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

[src]

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

[src]

This method tests for !=.

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

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

[src]

Creates a value from an iterator. Read more

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

[src]

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

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

[src]

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

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

[src]

Immutably borrows from an owned value. Read more

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

[src]

Mutably borrows from an owned value. Read more

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Mutably dereferences the value.

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

[src]

Formats the value using the given formatter. Read more

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

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

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

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

Auto Trait Implementations

impl<T> Send for Tree<T> where
    T: Send

impl<T> Sync for Tree<T> where
    T: Sync