[][src]Struct trees::linked::fully::onto_iter::Subnode

pub struct Subnode<'a, T: 'a> { /* fields omitted */ }

Wrapper of Node for allowing modification of parent or sib links. Any Node that is the root of some Tree is impossible to be Subnode.

Methods

impl<'a, T: 'a> Subnode<'a, T>[src]

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

Insert sib tree before self. The newly inserted node will not be iterated over by the currently running iterator.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
for mut sub in tree.root_mut().onto_iter() { sub.insert_before( tr(3) ); }
assert_eq!( tree.to_string(), "0( 3 1 3 2 )" );

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

Insert sib tree after self. The newly inserted node will not be iterated over by the currently running iterator.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
for mut sub in tree.root_mut().onto_iter() { sub.insert_after( tr(3) ); }
assert_eq!( tree.to_string(), "0( 1 3 2 3 )" );

pub fn depart(self) -> Tree<T>[src]

The subtree departs from its parent and becomes an indepent Tree.

Examples

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

let mut forest = -tr(1)-tr(2)-tr(3);
//for sub in forest.onto_iter() { sub.depart(); }
//forest.onto_iter().next().unwrap().depart();
//assert_eq!( forest, fr() );

Methods from Deref<Target = Node<T>>

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

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

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 );

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

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 );

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

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

pub fn forest(&self) -> &Forest<T>[src]

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 )" );

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

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

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

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

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /(tr(1)-tr(2)-tr(3));
tree.iter().for_each( |child| assert_eq!( child.parent(), Some( tree.root() )));

Important traits for Iter<'a, T>
pub fn iter<'a, 's: 'a>(&'s self) -> Iter<'a, T>[src]

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 );

pub fn bfs(&self) -> BfsTree<Splitted<Iter<T>>>[src]

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 }},
]);

Trait Implementations

impl<'a, T: 'a> Deref for Subnode<'a, T>[src]

type Target = Node<T>

The resulting type after dereferencing.

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for Subnode<'a, T> where
    T: RefUnwindSafe

impl<'a, T> !Send for Subnode<'a, T>

impl<'a, T> !Sync for Subnode<'a, T>

impl<'a, T> Unpin for Subnode<'a, T>

impl<'a, T> !UnwindSafe for Subnode<'a, T>

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