[][src]Struct trees::linked::fully::tree::Tree

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

A non-nullable tree

Methods

impl<T> Tree<T>[src]

pub fn new(data: T) -> Self[src]

Creates a Tree with given data on heap.

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

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

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

Removes and returns the given Tree's children.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
assert_eq!( tree.abandon().to_string(), "( 1 2 )" );
assert_eq!( tree, tr(0) );

pub fn into_bfs(self) -> BfsTree<Splitted<IntoIter<T>>>[src]

Provides a forward iterator with owned data 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.into_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 }},
]);

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

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

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

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

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

type Target = Node<T>

The resulting type after dereferencing.

impl<T: Display> Display for Tree<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<'a, T: Clone> Div<&'a Tree<T>> for Tree<T>[src]

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

impl<'a, T: Clone> Div<()> 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> Div<Tree<T>> for Tree<T>[src]

type Output = Tree<T>

The resulting type after applying the / operator.

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

type Output = Tree<T>

The resulting type after applying the / operator.

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

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

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

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

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

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

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

impl<T> Into<Tree<T>> for TreeWalk<T>[src]

impl<T> IntoIterator for Tree<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> Neg for Tree<T>[src]

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

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

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

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

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

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

type Item = T

type Iter = IntoIter<T>

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

type Output = Forest<T>

The resulting type after applying the - operator.

impl<'a, T: Clone> Sub<&'a Tree<T>> for &'a Tree<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 Tree<T>> for &'a Forest<T>[src]

type Output = Forest<T>

The resulting type after applying the - operator.

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

type Output = Forest<T>

The resulting type after applying the - operator.

impl<'a, T: Clone> Sub<Tree<T>> for &'a Tree<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.

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

Auto Trait Implementations

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

impl<T> Unpin for Tree<T>

impl<T> UnwindSafe for Tree<T> where
    T: RefUnwindSafe + UnwindSafe

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.