Struct trees::linked::fully::forest::Forest

source ·
pub struct Forest<T> { /* private fields */ }
Expand description

A nullable forest

Implementations

Makes an empty Forest.

Returns the number of child nodes in Forest.

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

Returns the number of all subnodes in Forest.

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

Returns true if the Forest is empty.

This operation should compute in O(1) time.

Examples
use trees::linked::fully::{tr,fr};
let mut forest = fr();
assert!( forest.is_empty() );
forest.push_back( tr(1) ); 
assert!( !forest.is_empty() );

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

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.

Adds the tree as the first child.

Examples
use trees::linked::fully::{tr,fr};
let mut forest = fr();
forest.push_front( tr(1) );
assert_eq!( forest.to_string(), "( 1 )" );
forest.push_front( tr(2) );
assert_eq!( forest.to_string(), "( 2 1 )" );

Adds the tree as the first child.

Examples
use trees::linked::fully::{tr,fr};
let mut forest = fr();
forest.push_back( tr(1) );
assert_eq!( forest.to_string(), "( 1 )" );
forest.push_back( tr(2) );
assert_eq!( forest.to_string(), "( 1 2 )" );

remove and return the first child

Examples
use trees::linked::fully::tr;
let mut forest = -tr(1)-tr(2);
assert_eq!( forest.pop_front(), Some( tr(1) ));
assert_eq!( forest.to_string(), "( 2 )" );
assert_eq!( forest.pop_front(), Some( tr(2) ));
assert_eq!( forest.to_string(), "()" );

remove and return the first child

Examples
use trees::linked::fully::tr;
let mut forest = -tr(1)-tr(2);
assert_eq!( forest.pop_back(), Some( tr(2) ));
assert_eq!( forest.to_string(), "( 1 )" );
assert_eq!( forest.pop_back(), Some( tr(1) ));
assert_eq!( forest.to_string(), "()" );

merge the forest at front

Examples
use trees::linked::fully::{tr,fr};
let mut forest = fr();
forest.prepend( -tr(0)-tr(1) );
assert_eq!( forest.to_string(), "( 0 1 )" );
forest.prepend( -tr(2)-tr(3) );
assert_eq!( forest.to_string(), "( 2 3 0 1 )" );

merge the forest at back

Examples
use trees::linked::fully::{tr,fr};
let mut forest = fr();
forest.append( -tr(0)-tr(1) );
assert_eq!( forest.to_string(), "( 0 1 )" );
forest.append( -tr(2)-tr(3) );
assert_eq!( forest.to_string(), "( 0 1 2 3 )" );

Provides a forward iterator over child Nodes

Examples
use trees::linked::fully::{tr,fr};

let forest = fr::<i32>();
assert_eq!( forest.iter().next(), None );

let forest = -tr(1)-tr(2);
let mut iter = forest.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 );
👎Deprecated since 0.2.0: please use iter instead

Provides a forward iterator over child Nodes with mutable references.

Examples
use trees::linked::fully::{tr,fr};

let mut forest = fr::<i32>();
assert_eq!( forest.iter_mut().next(), None );

let mut forest = -tr(1)-tr(2);
for child in forest.iter_mut() { child.data *= 10; }
assert_eq!( forest.to_string(), "( 10 20 )" );
👎Deprecated since 0.2.0: please use iter_mut instead

Provide an iterator over Forest’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,fr};

let forest = fr::<i32>();
let visits = forest.bfs().iter.collect::<Vec<_>>();
assert!( visits.is_empty() );

let forest = -( tr(1)/tr(2)/tr(3) ) -( tr(4)/tr(5)/tr(6) );
let visits = forest.bfs().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    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,fr};

let mut forest = fr::<i32>();
let visits = forest.bfs_mut().iter.collect::<Vec<_>>();
assert!( visits.is_empty() );

let mut forest = -( tr(1)/tr(2)/tr(3) ) -( tr(4)/tr(5)/tr(6) );
let visits = forest.bfs_mut().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    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 }},
]);

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

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

let forest = fr::<i32>();
let visits = forest.into_bfs().iter.collect::<Vec<_>>();
assert!( visits.is_empty() );

let forest = -( tr(1)/tr(2)/tr(3) ) -( tr(4)/tr(5)/tr(6) );
let visits = forest.into_bfs().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    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 }},
]);

Trait Implementations

Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Executes the destructor for this type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Converts to this type from the input type.
Creates a value from an iterator. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Converts this type into the (usually inferred) input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
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
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.