Struct trees::linked::singly::walk::ForestWalk [−][src]
Forest traversal
Implementations
impl<T> ForestWalk<T>
[src]
pub fn get(&self) -> Option<Visit<'_, T>>
[src]
Returns the current node in the forest traversal, or None
if the traversal is completed.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = -tr(1)-tr(2)-tr(3); let walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Leaf( tr(1).root() )));
pub fn forward(&mut self)
[src]
Depth first search on ForestWalk
.
Preorder or postorder at will.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = - ( tr(1)/tr(2)/tr(3) ) - ( tr(4)/tr(5)/tr(6) ); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(2).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(3).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::End ( (tr(1)/tr(2)/tr(3)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Begin( (tr(4)/tr(5)/tr(6)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(5).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(6).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::End ( (tr(4)/tr(5)/tr(6)).root() ))); walk.forward(); assert_eq!( walk.get(), None ); walk.forward(); assert_eq!( walk.get(), None ); walk.forward();
pub fn next(&mut self) -> Option<Visit<'_, T>>
[src]
Advance the cursor and return the newly visited node.
NOTICE: the FIRST node in the traversal can NOT be accessed via next() call.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = -tr(1)-tr(2)-tr(3); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.next(), Some( Visit::Leaf( tr(2).root() ))); assert_eq!( walk.next(), Some( Visit::Leaf( tr(3).root() ))); assert_eq!( walk.next(), None ); assert_eq!( walk.next(), None );
pub fn to_parent(&mut self) -> Option<Visit<'_, T>>
[src]
Set the cursor to the current node’s parent and returns it, or None
if it has no parent.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = - ( tr(1)/tr(2)/tr(3) ) - ( tr(4)/tr(5)/tr(6) ); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(2).root() ))); assert_eq!( walk.to_parent(), Some( Visit::End( (tr(1)/tr(2)/tr(3)).root() )));
pub fn get_parent(&self) -> Option<&Node<T>>
[src]
Returns the parent of current node, or None
if it has no parent.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = - ( tr(1)/tr(2)/tr(3) ) - ( tr(4)/tr(5)/tr(6) ); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); assert_eq!( walk.get_parent(), None ); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(2).root() ))); assert_eq!( walk.get_parent(), Some( (tr(1)/tr(2)/tr(3)).root() ));
pub fn to_child(&mut self, n: usize) -> Option<Visit<'_, T>>
[src]
Set the cursor to the current node’s n
-th child and returns it, or None
if it has no child.
Notice that n == 0
indicating the first child.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = - ( tr(1)/tr(2)/tr(3) ) - ( tr(4)/tr(5)/tr(6) ); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); walk.to_child( 1 ); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(3).root() )));
pub fn to_sib(&mut self, n: usize) -> Option<Visit<'_, T>>
[src]
Set the cursor to the current node’s next n
-th sibling and returns it, or None
if such sibling does not exist.
Returns the current node if n == 0.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = -tr(1)-tr(2)-tr(3); let mut walk = ForestWalk::from( forest ); assert_eq!( walk.get(), Some( Visit::Leaf( tr(1).root() ))); assert_eq!( walk.to_sib( 0 ), Some( Visit::Leaf( tr(1).root() ))); assert_eq!( walk.to_sib( 2 ), Some( Visit::Leaf( tr(3).root() )));
pub fn revisit(&mut self)
[src]
Revisit a Node
that reached Visit::End
.
No effect on Visit::Begin
or Visit::Leaf
.
Examples
use trees::linked::singly::{tr,Visit,ForestWalk}; let forest = - ( tr(1)/tr(2)/tr(3) ) - ( tr(4)/tr(5)/tr(6) ); let mut walk = ForestWalk::from( forest ); for _ in 0..3 { walk.revisit(); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); for _ in 0..3 { walk.revisit(); assert_eq!( walk.get(), Some( Visit::Begin( (tr(1)/tr(2)/tr(3)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(2).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(3).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::End ( (tr(1)/tr(2)/tr(3)).root() ))); } walk.forward(); for _ in 0..3 { walk.revisit(); assert_eq!( walk.get(), Some( Visit::Begin( (tr(4)/tr(5)/tr(6)).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(5).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::Leaf ( tr(6).root() ))); walk.forward(); assert_eq!( walk.get(), Some( Visit::End ( (tr(4)/tr(5)/tr(6)).root() ))); } walk.forward(); }
Trait Implementations
impl<T: Default> Default for ForestWalk<T>
[src]
fn default() -> ForestWalk<T>
[src]
impl<T> From<Forest<T>> for ForestWalk<T>
[src]
impl<T> Into<Forest<T>> for ForestWalk<T>
[src]
impl<T: Send> Send for ForestWalk<T>
[src]
impl<T: Sync> Sync for ForestWalk<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for ForestWalk<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Unpin for ForestWalk<T>
impl<T> UnwindSafe for ForestWalk<T> where
T: RefUnwindSafe + UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
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, 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>,