[][src]Struct trees::forest::Forest

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

List of Nodes as its children.

Implementations

impl<T> Forest<T>[src]

pub fn new() -> Forest<T>[src]

Makes an empty Forest.

pub fn from_tuple<Tuple, Shape>(tuple: Tuple) -> Self where
    Tuple: TupleForest<T, Shape>, 
[src]

Construct forest from tuple notations.

Examples

use trees::{Forest, tr};

let forest = Forest::<i32>::from_tuple(( 0, (1,2), (3,4) ));
assert_eq!( forest, -tr(0) -tr(1)/tr(2) -tr(3)/tr(4) );
assert_eq!( forest.to_string(), "( 0 1( 2 ) 3( 4 ) )" );

pub fn has_no_child(&self) -> bool[src]

Returns true if Forest is empty.

Examples

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

pub fn degree(&self) -> usize[src]

Returns the number of child nodes in Forest.

Examples

use trees::Forest;
let forest = Forest::<i32>::from_tuple(( 0, (1,2), (3,4) ));
assert_eq!( forest.degree(), 3 );

pub fn node_count(&self) -> usize[src]

Returns the number of all child nodes in Forest.

Examples

use trees::Forest;
let forest = Forest::<i32>::from_tuple(( 0, (1,2), (3,4) ));
assert_eq!( forest.node_count(), 5 );

pub fn iter<'a, 's: 'a>(&'s self) -> Iter<'a, T>

Notable traits for Iter<'a, T>

impl<'a, T: 'a> Iterator for Iter<'a, T> type Item = &'a Node<T>;
[src]

Provides a forward iterator over child Nodes.

Examples

use trees::{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 );

pub fn iter_mut<'a, 's: 'a>(&'s mut self) -> IterMut<'a, T>

Notable traits for IterMut<'a, T>

impl<'a, T: 'a> Iterator for IterMut<'a, T> type Item = Pin<&'a mut Node<T>>;
[src]

Provides a forward iterator over child Nodes with mutable references.

Examples

use trees::Forest;

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

let mut forest = Forest::<i32>::from_tuple(( 1, 2 ));
forest.iter_mut().for_each( |mut child| { *child.data_mut() *= 10; });
assert_eq!( forest.to_string(), "( 10 20 )" );

pub fn front(&self) -> Option<&Node<T>>[src]

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

pub fn front_mut(&mut self) -> Option<Pin<&mut Node<T>>>[src]

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

pub fn back(&self) -> Option<&Node<T>>[src]

pub fn back_mut(&mut self) -> Option<Pin<&mut Node<T>>>[src]

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

pub fn push_front(&mut self, tree: Tree<T>)[src]

Add the tree as the first child.

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_front( Tree::new(1) );
assert_eq!( forest.to_string(), "( 1 )" );
forest.push_front( Tree::new(2) );
assert_eq!( forest.to_string(), "( 2 1 )" );

pub fn push_back(&mut self, tree: Tree<T>)[src]

Add the tree as the last child.

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_back( Tree::new(1) );
assert_eq!( forest.to_string(), "( 1 )" );
forest.push_back( Tree::new(2) );
assert_eq!( forest.to_string(), "( 1 2 )" );

pub fn pop_front(&mut self) -> Option<Tree<T>>[src]

Remove and return the first child.

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_back( Tree::new(1) );
forest.push_back( Tree::new(2) );
assert_eq!( forest.to_string(), "( 1 2 )" );
assert_eq!( forest.pop_front(), Some( Tree::new(1) ));
assert_eq!( forest.to_string(), "( 2 )" );
assert_eq!( forest.pop_front(), Some( Tree::new(2) ));
assert_eq!( forest.to_string(), "()" );

pub fn pop_back(&mut self) -> Option<Tree<T>>[src]

Remove and return the first child.

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_back( Tree::new(1) );
forest.push_back( Tree::new(2) );
assert_eq!( forest.to_string(), "( 1 2 )" );
assert_eq!( forest.pop_back(), Some( Tree::new(2) ));
assert_eq!( forest.to_string(), "( 1 )" );
assert_eq!( forest.pop_back(), Some( Tree::new(1) ));
assert_eq!( forest.to_string(), "()" );

pub fn prepend(&mut self, forest: Forest<T>)[src]

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

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_back( Tree::new(1) );
forest.push_back( Tree::new(2) );
let mut forest2 = Forest::new();
forest2.push_back( Tree::new(3) );
forest2.push_back( Tree::new(4) );
forest.prepend( forest2 );
assert_eq!( forest.to_string(), "( 3 4 1 2 )" );

pub fn append(&mut self, forest: Forest<T>)[src]

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

Examples

use trees::{Tree, Forest};
let mut forest = Forest::new();
forest.push_back( Tree::new(1) );
forest.push_back( Tree::new(2) );
let mut forest2 = Forest::new();
forest2.push_back( Tree::new(3) );
forest2.push_back( Tree::new(4) );
forest.append( forest2 );
assert_eq!( forest.to_string(), "( 1 2 3 4 )" );

impl<T> Forest<T>[src]

pub fn bfs(&self) -> BfsForest<Splitted<Iter<'_, T>>>[src]

Provides a forward iterator in a breadth-first manner.

Examples

use trees::Forest;

let forest = Forest::from_tuple(( (1,2,3), (4,5,6), ));
let visits = forest.bfs().iter
    .map( |visit| (*visit.data, visit.size.degree, visit.size.descendants ))
    .collect::<Vec<_>>();
assert_eq!( visits, vec![ (1, 2, 2), (4, 2, 2), (2, 0, 0), (3, 0, 0), (5, 0, 0), (6, 0, 0), ]);

pub fn bfs_mut(&mut self) -> BfsForest<Splitted<IterMut<'_, T>>>[src]

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

Examples

use trees::Forest;

let mut forest = Forest::<i32>::from_tuple(( (1,2,3), (4,5,6), ));
forest.bfs_mut().iter
    .zip( 0.. )
    .for_each( |(visit,nth)| *visit.data += 10 * nth );
assert_eq!( forest, Forest::from_tuple(( (1,(22,),(33,)), (14,(45,),(56,)), )));

pub fn into_bfs(self: Forest<T>) -> BfsForest<Splitted<IntoIter<T>>>[src]

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

Examples

use trees::{bfs,Size};
use trees::Forest;

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

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

Trait Implementations

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

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

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

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

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

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

impl<T, Iter> From<BfsForest<Iter>> for Forest<T> where
    Iter: Iterator<Item = Visit<T>>, 
[src]

impl<T> From<Forest<T>> for ForestWalk<T>[src]

impl<T> From<ForestWalk<T>> for Forest<T>[src]

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

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

type Item = Tree<T>

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

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

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

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

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

Auto Trait Implementations

impl<T> !RefUnwindSafe for Forest<T>[src]

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

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

impl<T> Unpin for Forest<T> where
    T: Unpin
[src]

impl<T> !UnwindSafe for Forest<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> TupleTree<T, ()> for T[src]