Struct trees::potted::node::Node[][src]

pub struct Node<T> {
    pub data: T,
    // some fields omitted
}

Fields

data: T

Implementations

impl<T> Node<T>[src]

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

Returns true if this node has no child nodes, otherwise false.

Examples

use trees::potted::{Tree,Node,TreeData,TupleTree};

let mut tree = Tree::<_>::from(( 1, ));
let root: &mut Node<_> = tree.root_mut();
assert!( root.is_leaf() );

root.append_tr(( 2, ));
assert!( !root.is_leaf() );

pub fn data(&self) -> &T[src]

👎 Deprecated since 0.2.1:

please use data field instead

pub fn data_mut(&mut self) -> &mut T[src]

👎 Deprecated since 0.2.1:

please use data field instead

pub fn set_data(&mut self, data: T)[src]

👎 Deprecated since 0.2.1:

please use data field instead

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

Returns reference of parent node if exists, otherwise None.

Examples

use trees::potted::{Tree,Node,TreeData,TupleTree};

let mut tree = Tree::<_>::from(( 1, 2 ));
let root  : &Node<_> = tree.root();
let child : &Node<_> = root.iter().next().unwrap();
assert_eq!( root.parent(),  None );
assert_eq!( child.parent(), Some( root ));

pub fn nth_child(&self, n: usize) -> Option<&Self>[src]

Returns the immutable reference of n-th child node if exists, otherwise None. Note that it is zero-based index.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let tree: Tree<_> = ( "a", "b", "c", "d", "e" ).into();
assert_eq!( tree.root().nth_child(2).unwrap().data, "d" );

pub fn nth_child_mut(&mut self, n: usize) -> Option<&mut Self>[src]

Returns the mutable reference of n-th child node if exists, otherwise None. Note that it is zero-based index.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( "a", "b", "c", "d", "e" ).into();
tree.root_mut().nth_child_mut(2).unwrap().data = "D";
assert_eq!( tree.to_string(), "a( b c D e )" );

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::potted::{Tree,TreeData,TupleTree};

let tree: Tree<_> = ( "a","b","c","d" ).into();
let mut iter = tree.root().iter();
assert_eq!( iter.next().unwrap().data, "b" );
assert_eq!( iter.next().unwrap().data, "c" );
assert_eq!( iter.next().unwrap().data, "d" );
assert_eq!( iter.next(), None );
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 = &'a mut Node<T>;
[src]

Provides a forward iterator over child nodes with mutable references.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( 0, 1, 2, 3 ).into();
for child in tree.root_mut().iter_mut() {
    child.data *= 10;
}
assert_eq!( tree.root().to_string(), "0( 10 20 30 )" );

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::potted::Tree;

let tree: Tree<_> = (0, (1,2,3), (4,5,6) ).into();
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 prepend_tr<Tr>(&mut self, tuple: Tr) where
    Tr: TupleTree<Data = T>, 
[src]

Add the tuple tree as the first child.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( "a", "b", "c" ).into();
tree.root_mut().prepend_tr(( "d", "e", "f" ));
assert_eq!( tree.root().to_string(), "a( d( e f ) b c )" );

pub fn append_tr<Tr>(&mut self, tuple: Tr) where
    Tr: TupleTree<Data = T>, 
[src]

Add the tuple tree as the last child.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( "a", "b", "c" ).into();
tree.root_mut().append_tr(( "d", "e", "f" ));
assert_eq!( tree.root().to_string(), "a( b c d( e f ) )" );

pub fn prepend_fr<Fr>(&mut self, tuple: Fr) where
    Fr: TupleForest<Data = T>, 
[src]

Add the tuple forest as the first-n children.

Examples

use trees::potted::{Tree,TreeData,TupleTree,fr};

let mut tree: Tree<_> = ( "a", "b", "c" ).into();
tree.root_mut().prepend_fr(( fr(), "d", "e", "f" ));
assert_eq!( tree.root().to_string(), "a( d e f b c )" );

pub fn append_fr<Fr>(&mut self, tuple: Fr) where
    Fr: TupleForest<Data = T>, 
[src]

Add the tuple forest as the last-n children.

Examples

use trees::potted::{Tree,TreeData,TupleTree,fr};

let mut tree: Tree<_> = ( "a", "b", "c" ).into();
tree.root_mut().append_fr(( fr(), "d", "e", "f" ));
assert_eq!( tree.root().to_string(), "a( b c d e f )" );

pub fn insert_tr<Tuple>(&mut self, nth: usize, tuple: Tuple) where
    Tuple: TupleTree<Data = T>, 
[src]

Insert the tuple tree as the n-th child. Note that it is zero-based index.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( "a", "b", "c", "d", "e" ).into();
tree.root_mut().insert_tr( 2, ("f",) );
assert_eq!( tree.root().to_string(), "a( b c f d e )" );

pub fn drop_front(&mut self)[src]

Drop the first child.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( 1, 2, 3, 4 ).into();
tree.root_mut().drop_front();
assert_eq!( tree.root().to_string(), "1( 3 4 )" );

pub fn drop_back(&mut self)[src]

Drop the last child.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( 1, 2, 3, 4 ).into();
tree.root_mut().drop_back();
assert_eq!( tree.root().to_string(), "1( 2 3 )" );

pub fn drop_nth(&mut self, nth: usize)[src]

Drop the n-th child.

Examples

use trees::potted::{Tree,TreeData,TupleTree};

let mut tree: Tree<_> = ( "a", "b", "c", "d", "e" ).into();
tree.root_mut().drop_nth( 2 );
assert_eq!( tree.root().to_string(), "a( b c e )" );

pub fn prepend_bfs<Iter>(&mut self, bfs: Bfs<Iter>) where
    Iter: Iterator<Item = Visit<T>>, 
[src]

Add tree(s) from a bfs iterator as the first child(ren).

Examples

use trees::linked::fully::tr;
use trees::linked::singly::tr as t;
use trees::potted::{Tree,TreeData,TupleTree};

let mut potted: Tree<_> = ( 0, (1,2), (3,4) ).into();

let linked = tr(5) /tr(6) /tr(7);
potted.root_mut().nth_child_mut(0).unwrap().prepend_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 5( 6 7 ) 2 ) 3( 4 ) )" );

let linked = t(8) /t(9) /t(10);
potted.root_mut().nth_child_mut(1).unwrap().prepend_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 5( 6 7 ) 2 ) 3( 8( 9 10 ) 4 ) )" );

Examples

use trees::linked::fully::tr;
use trees::linked::singly::tr as t;
use trees::potted::{Tree,TreeData,TupleTree};

let mut potted: Tree<_> = ( 0, (1,2), (3,4) ).into();

let linked = tr(5) -tr(6) -tr(7);
potted.root_mut().nth_child_mut(0).unwrap().prepend_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 5 6 7 2 ) 3( 4 ) )" );

//let linked = t(8) /t(9) /t(10);
//potted.root_mut().nth_child_mut(1).unwrap().prepend_bfs( linked.into_bfs() );
//assert_eq!( potted.root().to_string(), "0( 1( 5 6 7 2 ) 3( 8 9 10 4 ) )" );

pub fn append_bfs<Iter>(&mut self, bfs: Bfs<Iter>) where
    Iter: Iterator<Item = Visit<T>>, 
[src]

Add tree(s) from a bfs iterator as the last child(ren).

Examples

use trees::linked::fully::tr;
use trees::linked::singly::tr as t;
use trees::potted::{Tree,TreeData,TupleTree};

let mut potted: Tree<_> = ( 0, (1,2), (3,4) ).into();

let linked = tr(5) /tr(6) /tr(7);
potted.root_mut().nth_child_mut(0).unwrap().append_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 2 5( 6 7 ) ) 3( 4 ) )" );

let linked = t(8) /t(9) /t(10);
potted.root_mut().nth_child_mut(1).unwrap().append_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 2 5( 6 7 ) ) 3( 4 8( 9 10 ) ) )" );

Examples

use trees::linked::fully::tr;
use trees::linked::singly::tr as t;
use trees::potted::{Tree,TreeData,TupleTree};

let mut potted: Tree<_> = ( 0, (1,2), (3,4) ).into();

let linked = tr(5) -tr(6) -tr(7);
potted.root_mut().nth_child_mut(0).unwrap().append_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 2 5 6 7 ) 3( 4 ) )" );

let linked = t(8) -t(9) -t(10);
potted.root_mut().nth_child_mut(1).unwrap().append_bfs( linked.into_bfs().wrap() );
assert_eq!( potted.root().to_string(), "0( 1( 2 5 6 7 ) 3( 4 8 9 10 ) )" );

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::potted::Tree;

let mut tree: Tree<_> = (0, (1,2,3), (4,5,6) ).into();
let visits = tree.root_mut().bfs_mut().iter.collect::<Vec<_>>();
assert_eq!( visits, vec![
    bfs::Visit{ data: &mut 0, size: Size{ degree: 2, node_cnt: 7 }},
    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 }},
]);

Trait Implementations

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

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

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

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

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

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

impl<T> Indexed 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<'a, T: 'a> IntoIterator for &'a mut Node<T>[src]

type Item = Self

The type of the elements being iterated over.

type IntoIter = IterMut<'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<'a, T: 'a> Split for &'a mut Node<T>[src]

type Item = &'a mut T

type Iter = IterMut<'a, T>

Auto Trait Implementations

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

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

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

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