Struct trees::potted::forest::Forest [−][src]
Implementations
impl<T> Forest<T>
[src]
pub fn new() -> Self
[src]
Makes an empty Forest
.
pub fn adopt(self, root_data: T) -> Tree<T>
[src]
Joins the root data in the forest to make a tree.
Examples
use trees::potted::{Forest,fr}; let forest: Forest<_> = ( fr(), (2,3,4), (5,6,7) ).into(); let tree = forest.adopt( 1 ); assert_eq!( tree.root().to_string(), "1( 2( 3 4 ) 5( 6 7 ) )" );
pub fn pot(&self) -> &Pot<T>
[src]
For debug purpose.
pub fn degree(&self) -> usize
[src]
Returns the number of child nodes in Forest
.
Examples
use trees::potted::{Forest,TupleForest,TreeData,fr}; let forest = Forest::from(( fr(), 1, 2, 3 )); assert_eq!( forest.degree(), 3 );
pub fn is_empty(&self) -> bool
[src]
Returns true
if this forest has no child nodes, otherwise false
.
Examples
use trees::potted::{Forest,TupleForest,TreeData,fr}; let forest = Forest::<i32>::new(); assert!( forest.is_empty() ); let forest = Forest::from(( fr(), 1, 2, 3 )); assert!( !forest.is_empty() );
pub fn iter(&self) -> Iter<'_, T>ⓘ
[src]
Provides a forward iterator over child nodes
Examples
use trees::potted::{Forest,TreeData,TupleForest,fr}; let forest: Forest<_> = ( fr(), 1, 2, 3 ).into(); let mut iter = forest.iter(); assert_eq!( iter.next().unwrap().data, 1 ); assert_eq!( iter.next().unwrap().data, 2 ); assert_eq!( iter.next().unwrap().data, 3 ); assert_eq!( iter.next(), None ); assert_eq!( iter.next(), None );
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘ
[src]
Provides a forward iterator over child nodes with mutable references.
Examples
use trees::potted::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), 1, 2, 3 ).into(); for child in forest.iter_mut() { child.data *= 10; } assert_eq!( forest.to_string(), "( 10 20 30 )" );
pub fn bfs<'a, 's: 'a>(&'s self) -> BfsForest<Splitted<Iter<'a, T>>>
[src]
Provides a forward iterator in a breadth-first manner
Examples
use trees::{bfs,Size}; use trees::potted::{Forest,fr}; let forest: Forest<_> = ( fr(), (1,2,3), (4,5,6) ).into(); let visits = forest.bfs().iter.collect::<Vec<_>>(); assert_eq!( visits, vec![ 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<'a, 's: 'a>(&'s mut self) -> BfsForest<Splitted<IterMut<'a, T>>>
[src]
Provides a forward iterator with mutable references in a breadth-first manner
Examples
use trees::{bfs,Size}; use trees::potted::{Forest,fr}; let mut forest: Forest<_> = ( fr(), (1,2,3), (4,5,6) ).into(); let visits = forest.bfs_mut().iter.collect::<Vec<_>>(); assert_eq!( visits, vec![ 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 }}, ]);
pub fn into_bfs<'a>(self) -> BfsForest<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::{Forest,fr}; let mut forest: Forest<_> = (fr(), (1,2,3), (4,5,6) ).into(); let visits = forest.into_bfs().iter.collect::<Vec<_>>(); assert_eq!( visits, vec![ 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 nth_child(&self, n: usize) -> Option<&Node<T>>
[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::{Forest,TreeData,TupleForest,fr}; let forest: Forest<_> = ( fr(), "a", "b", "c", "d", "e" ).into(); assert_eq!( forest.nth_child(2).unwrap().data, "c" );
pub fn nth_child_mut(&mut self, n: usize) -> Option<&mut Node<T>>
[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::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c", "d", "e" ).into(); forest.nth_child_mut(2).unwrap().data = "C"; assert_eq!( forest.to_string(), "( a b C d e )" );
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::{Forest,TreeData,TupleTree,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c" ).into(); forest.prepend_tr(( "d", "e", "f" )); assert_eq!( forest.to_string(), "( d( e f ) a 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::{Forest,TreeData,TupleTree,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c" ).into(); forest.append_tr(( "d", "e", "f" )); assert_eq!( forest.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::{Forest,TreeData,TupleTree,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c", "d", "e" ).into(); forest.insert_tr( 2, ("f",) ); assert_eq!( forest.to_string(), "( a b f c d e )" );
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::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c" ).into(); forest.prepend_fr(( fr(), "d", "e", "f" )); assert_eq!( forest.to_string(), "( d e f a 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::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c" ).into(); forest.append_fr(( fr(), "d", "e", "f" )); assert_eq!( forest.to_string(), "( a b c d e f )" );
pub fn drop_front(&mut self)
[src]
Drop the first child.
Examples
use trees::potted::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), 1, 2, 3, 4 ).into(); forest.drop_front(); assert_eq!( forest.to_string(), "( 2 3 4 )" );
pub fn drop_back(&mut self)
[src]
Drop the last child.
Examples
use trees::potted::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), 1, 2, 3, 4 ).into(); forest.drop_back(); assert_eq!( forest.to_string(), "( 1 2 3 )" );
pub fn drop_nth(&mut self, nth: usize)
[src]
Drop the n-th child.
Examples
use trees::potted::{Forest,TreeData,TupleForest,fr}; let mut forest: Forest<_> = ( fr(), "a", "b", "c", "d", "e" ).into(); forest.drop_nth( 2 ); assert_eq!( forest.to_string(), "( a b d 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::{Forest,TreeData,TupleForest,fr}; let mut potted: Forest<_> = ( fr(), (1,2), (3,4) ).into(); let linked = tr(5) /tr(6) /tr(7); potted.nth_child_mut(0).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 1( 5( 6 7 ) 2 ) 3( 4 ) )" ); let linked = t(8) /t(9) /t(10); potted.nth_child_mut(1).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 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::{Forest,TreeData,TupleForest,fr}; let mut potted: Forest<_> = ( fr(), (1,2), (3,4) ).into(); let linked = tr(5) -tr(6) -tr(7); potted.nth_child_mut(0).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 1( 5 6 7 2 ) 3( 4 ) )" ); let linked = t(8) -t(9) -t(10); potted.nth_child_mut(1).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 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::{Forest,TreeData,TupleForest,fr}; let mut potted: Forest<_> = ( fr(), (1,2), (3,4) ).into(); let linked = tr(5) /tr(6) /tr(7); potted.nth_child_mut(0).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 1( 5( 6 7 ) 2 ) 3( 4 ) )" ); let linked = t(8) /t(9) /t(10); potted.nth_child_mut(1).unwrap().prepend_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 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::{Forest,TreeData,TupleForest,fr}; let mut potted: Forest<_> = ( fr(), (1,2), (3,4) ).into(); let linked = tr(5) -tr(6) -tr(7); potted.nth_child_mut(0).unwrap().append_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 1( 2 5 6 7 ) 3( 4 ) )" ); let linked = t(8) -t(9) -t(10); potted.nth_child_mut(1).unwrap().append_bfs( linked.into_bfs().wrap() ); assert_eq!( potted.to_string(), "( 1( 2 5 6 7 ) 3( 4 8 9 10 ) )" );
Trait Implementations
impl<T: Debug> Debug for Forest<T>
[src]
impl<T> Default for Forest<T>
[src]
impl<T: Display> Display for Forest<T>
[src]
impl<T> Drop for Forest<T>
[src]
impl<T: Eq> Eq for Forest<T>
[src]
impl<T, Iter> From<BfsForest<Iter>> for Forest<T> where
Iter: Iterator<Item = Visit<T>>,
[src]
Iter: Iterator<Item = Visit<T>>,
impl<T, Tuple> From<Tuple> for Forest<T> where
Tuple: TupleForest<Data = T>,
[src]
Tuple: TupleForest<Data = T>,
impl<T: Hash> Hash for Forest<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 Forest<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<Forest<T>> for Forest<T>
[src]
impl<T: PartialOrd> PartialOrd<Forest<T>> for Forest<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Forest<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for Forest<T>
impl<T> !Sync for Forest<T>
impl<T> Unpin for Forest<T>
impl<T> UnwindSafe for Forest<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>,