Struct trees::Forest [] [src]

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

Collection of circularly-linked Trees

Methods

impl<T> Forest<T>
[src]

[src]

Makes an empty Forest

[src]

add the child as the first child

Examples

use trees::tr;

let mut forest = tr(1)-tr(2);
forest.push_front( tr(3) );
let mut iter = forest.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(3) );
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next(), None );

[src]

Add the child as the first child and return the Forest itself.

[src]

Removes and returns the tree at the front of the forest.

Examples

use trees::{tr,fr};

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

[src]

Appends the given tree at the end of this forest

Examples

use trees::tr;

let mut forest = tr(1)-tr(2);
forest.push_back( tr(3) );
let mut iter = forest.children();
assert_eq!( iter.next().unwrap().to_owned(), tr(1) );
assert_eq!( iter.next().unwrap().to_owned(), tr(2) );
assert_eq!( iter.next().unwrap().to_owned(), tr(3) );
assert_eq!( iter.next(), None );

[src]

Appends the given tree at the end of this forest and return the forest.

[src]

Merges two forests into one, and return it

Examples

use trees::{tr,fr};

let mut forest = fr().append( tr(1) ).append( tr(2) );
let f2 = fr().append( tr(3) ).append( tr(4) );
forest = forest.merge( f2 );
assert_eq!( forest, tr(1)-tr(2)-tr(3)-tr(4) );

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

Provides a forward iterator over the Forest's direct decendants

Examples

use trees::tr;

let forest = tr(1)/tr(2)/tr(3) - tr(4)/tr(5)/tr(6);
let mut iter = forest.children();
//assert_eq!( iter.next().unwrap().clone(), tr(1) /tr(2)/tr(3) );
//assert_eq!( iter.next().unwrap().clone(), tr(4) /tr(5)/tr(6) );
//assert_eq!( iter.next(), None );

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

Provides a forward iterator over the Forest's direct decendants with mutable references.

Examples

use trees::tr;

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

Important traits for SubtreeIter<T>
[src]

Provides an iterator over the Forest's subtrees for insert/remove at any position.

Examples

insert after

use trees::tr;

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

insert before

use trees::tr;

let mut forest = tr(1)-tr(3)-tr(4);
let mut iter = forest.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!( forest, 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 Forest is empty.

This operation should compute in O(1) time.

Examples

use trees::{tr,fr};

let mut forest = fr();
assert!( forest.is_empty() );
forest.push_back( tr(1) ); 
assert!( !forest.is_empty() );

Trait Implementations

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for IntoIter<T>
[src]

Consumes the Forest into an iterator yielding Trees.

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

[src]

Creates a value from 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: Clone> Clone for Forest<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: PartialEq> PartialEq for Forest<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 Forest<T>
[src]

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

[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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 Forest<T>
[src]

[src]

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

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<T> Default for Forest<T>
[src]

[src]

Returns the "default value" for a type. Read more

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

[src]

Executes the destructor for this type. Read more

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

[src]

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

1.3.0
[src]

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

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

[src]

Formats the value using the given formatter. Read more

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

[src]

Formats the value using the given formatter. Read more

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

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

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> 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.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.