[][src]Struct trees::linked::fully::node::Node

#[repr(C)]
pub struct Node<T> {
    pub data: T,
    // some fields omitted
}

Fields

data: T

Methods

impl<T> Node<T>[src]

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 forest_mut(&mut self) -> Pin<&mut Forest<T>>[src]

Returns the given Tree's children as a mutable borrowed Forest.

Examples

use trees::linked::fully::tr;
let mut tree = tr(0) /tr(1)/tr(2);
for mut child in tree.root_mut().forest_mut().iter_mut() { child.data *= 10; }
assert_eq!( tree.to_string(), "0( 10 20 )" );

pub fn first_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 last(&self) -> Option<&Node<T>>[src]

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

pub fn last_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 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() )));

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

Adds the tree as the first child.

Examples

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

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

Add the tree as the last child

Examples

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

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

Remove and return the first child

Examples

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

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

Remove and return the last child

Examples

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

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

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

Examples

use trees::linked::fully::tr;
let mut tree = tr(0);
tree.root_mut().prepend( -tr(1)-tr(2) );
assert_eq!( tree.to_string(), "0( 1 2 )" );
tree.root_mut().prepend( -tr(3)-tr(4) );
assert_eq!( tree.to_string(), "0( 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::linked::fully::tr;
let mut tree = tr(0);
tree.root_mut().append( -tr(1)-tr(2) );
assert_eq!( tree.to_string(), "0( 1 2 )" );
tree.root_mut().append( -tr(3)-tr(4) );
assert_eq!( tree.to_string(), "0( 1 2 3 4 )" );

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

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

Provides a forward iterator over child Nodes with mutable references.

Examples

use trees::linked::fully::tr;

let mut tree = tr(0);
assert_eq!( tree.root_mut().iter_mut().next(), None );

let mut tree = tr(0) /tr(1)/tr(2);
for mut child in tree.root_mut().iter_mut() { child.data *= 10; }
assert_eq!( tree.to_string(), "0( 10 20 )" );

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

Provide an iterator over Node's Subnodes for insert/remove at any position. See Subnode's document for more.

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

pub fn bfs_mut(&mut self) -> BfsTree<Splitted<IterMut<T>>>[src]

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

Examples

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

let mut tree = tr(0) /( tr(1)/tr(2)/tr(3) ) /( tr(4)/tr(5)/tr(6) );
let mut root = tree.root_mut();
root.bfs_mut().iter.zip( 0.. ).for_each( |(visit,nth)| (*visit.data) += 10 * nth );
assert_eq!( tree, tr(0) /( tr(11)/tr(32)/tr(43) ) /( tr(24)/tr(55)/tr(66) ));

Trait Implementations

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

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

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

type Target = Link

The resulting type after dereferencing.

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

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

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

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

impl<'a, T: 'a> IntoIterator for &'a Node<T>[src]

type Item = Self

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

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

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

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

impl<'a, T: 'a> Split for &'a Node<T>[src]

type Item = &'a T

type Iter = Iter<'a, T>

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

type Owned = Tree<T>

The resulting type after obtaining ownership.

Auto Trait Implementations

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

impl<T> !Send for Node<T>

impl<T> !Sync for Node<T>

impl<T> Unpin for Node<T> where
    T: Unpin

impl<T> UnwindSafe for Node<T> where
    T: 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<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.