pub trait Visitor: Sized {
type Item;
type NonLeafItem;
fn next(self) -> (Self::Item, Option<(Self::NonLeafItem, Self, Self)>);
fn level_remaining_hint(&self) -> (usize, Option<usize>) { ... }
fn with_depth(self, start_depth: Depth) -> LevelIter<Self> { ... }
fn zip<F: Visitor>(self, f: F) -> Zip<Self, F> { ... }
fn map<B, E, F: Fn(Self::Item, Option<Self::NonLeafItem>) -> (B, Option<E>)>(
self,
func: F
) -> Map<Self, F> { ... }
fn bfs_iter(self) -> BfsIter<Self> ⓘ { ... }
fn dfs_preorder_iter(self) -> DfsPreOrderIter<Self> ⓘ { ... }
fn dfs_inorder_iter(self) -> DfsInOrderIter<Self> ⓘ { ... }
fn dfs_preorder(
self,
func: impl FnMut(Self::Item, Option<Self::NonLeafItem>)
) { ... }
fn dfs_inorder(self, func: impl FnMut(Self::Item, Option<Self::NonLeafItem>)) { ... }
}
Expand description
The trait this crate revoles around. A complete binary tree visitor.
Required Associated Types§
sourcetype NonLeafItem
type NonLeafItem
A NonLeafItem item can be returned for non leafs.
Required Methods§
sourcefn next(self) -> (Self::Item, Option<(Self::NonLeafItem, Self, Self)>)
fn next(self) -> (Self::Item, Option<(Self::NonLeafItem, Self, Self)>)
Consume this visitor, and produce the element it was pointing to along with it’s children visitors.
Provided Methods§
sourcefn level_remaining_hint(&self) -> (usize, Option<usize>)
fn level_remaining_hint(&self) -> (usize, Option<usize>)
Return the levels remaining including the one that will be produced by consuming this iterator. So if you first made this object from the root for a tree of size 5, it should return 5. Think of is as height-depth. This is used to make good allocations when doing dfs and bfs. Defaults to (0,None)
sourcefn with_depth(self, start_depth: Depth) -> LevelIter<Self>
fn with_depth(self, start_depth: Depth) -> LevelIter<Self>
Iterator Adapter to also produce the depth each iteration.
sourcefn map<B, E, F: Fn(Self::Item, Option<Self::NonLeafItem>) -> (B, Option<E>)>(
self,
func: F
) -> Map<Self, F>
fn map<B, E, F: Fn(Self::Item, Option<Self::NonLeafItem>) -> (B, Option<E>)>(
self,
func: F
) -> Map<Self, F>
Map iterator adapter
sourcefn bfs_iter(self) -> BfsIter<Self> ⓘ
fn bfs_iter(self) -> BfsIter<Self> ⓘ
Provides an iterator that returns each element in bfs order.
sourcefn dfs_preorder_iter(self) -> DfsPreOrderIter<Self> ⓘ
fn dfs_preorder_iter(self) -> DfsPreOrderIter<Self> ⓘ
Provides a dfs preorder iterator. Unlike the callback version, This one relies on dynamic allocation for its stack.
fn dfs_inorder_iter(self) -> DfsInOrderIter<Self> ⓘ
sourcefn dfs_preorder(self, func: impl FnMut(Self::Item, Option<Self::NonLeafItem>))
fn dfs_preorder(self, func: impl FnMut(Self::Item, Option<Self::NonLeafItem>))
Calls the closure in dfs preorder (root,left,right). Takes advantage of the callstack to do dfs.
sourcefn dfs_inorder(self, func: impl FnMut(Self::Item, Option<Self::NonLeafItem>))
fn dfs_inorder(self, func: impl FnMut(Self::Item, Option<Self::NonLeafItem>))
Calls the closure in dfs preorder (left,right,root). Takes advantage of the callstack to do dfs.