Struct trees::potted::tree::Tree [−][src]
Implementations
impl<T> Tree<T>
[src]
pub fn root(&self) -> &Node<T>
[src]
pub fn root_mut(&mut self) -> &mut Node<T>
[src]
pub fn abandon(self) -> (T, Forest<T>)
[src]
Break the tree into root’s data and the children forest.
Examples
use trees::potted::Tree; let tree: Tree<_> = ( 1, (2,3,4), (5,6,7) ).into(); let ( root_data, forest ) = tree.abandon(); assert_eq!( root_data, 1 ); assert_eq!( forest.to_string(), "( 2( 3 4 ) 5( 6 7 ) )" );
pub fn pot(&self) -> &Pot<T>
[src]
For debug purpose.
pub fn into_bfs<'a>(self) -> BfsTree<MovedNodes<'a, T, Splitted<Iter<'a, T>>>>
[src]
Provides a forward iterator with owned data 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.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]
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]
please use data
field instead
pub fn data_mut(&mut self) -> &mut T
[src]
please use data
field instead
pub fn set_data(&mut self, data: T)
[src]
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>ⓘ
[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>ⓘ
[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]
Tr: TupleTree<Data = T>,
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]
Tr: TupleTree<Data = T>,
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]
Fr: TupleForest<Data = T>,
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]
Fr: TupleForest<Data = T>,
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]
Tuple: TupleTree<Data = T>,
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]
Iter: Iterator<Item = Visit<T>>,
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]
Iter: Iterator<Item = Visit<T>>,
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]
fn borrow_mut(&mut self) -> &mut Node<T>
[src]
impl<T: Debug> Debug for Tree<T>
[src]
impl<T> Deref for Tree<T>
[src]
impl<T> DerefMut for Tree<T>
[src]
impl<T: Display> Display for Tree<T>
[src]
impl<T> Drop for Tree<T>
[src]
impl<T: Eq> Eq for Tree<T>
[src]
impl<T, Iter> From<BfsTree<Iter>> for Tree<T> where
Iter: Iterator<Item = Visit<T>>,
[src]
Iter: Iterator<Item = Visit<T>>,
impl<T, Tuple> From<Tuple> for Tree<T> where
Tuple: TupleTree<Data = T>,
[src]
Tuple: TupleTree<Data = T>,
impl<T: Hash> Hash for Tree<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: Ord> Ord for Tree<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<Tree<T>> for Tree<T>
[src]
impl<T: PartialOrd> PartialOrd<Tree<T>> for Tree<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Tree<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for Tree<T>
impl<T> !Sync for Tree<T>
impl<T> Unpin for Tree<T>
impl<T> UnwindSafe for Tree<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,