Class TreeTraversal<TEdge, TNode>
Base class for all tree traversal strategies, such as DepthFirstTraversal<TEdge, TNode> and BreadthFirstTraversal<TEdge, TNode> strategies, which are different strategies of traversing a IRecImmDictIndexedTreeNode<TEdge, TNode> structure top-down.
Inheritance
Implements
Inherited Members
Namespace: MoreStructures.RecImmTrees.Visitor
Assembly: MoreStructures.dll
Syntax
public abstract class TreeTraversal<TEdge, TNode> : IVisitStrategy<TNode, TreeTraversalVisit<TEdge, TNode>> where TEdge : IRecImmDictIndexedTreeEdge<TEdge, TNode> where TNode : IRecImmDictIndexedTreeNode<TEdge, TNode>
Type Parameters
Name | Description |
---|---|
TEdge | |
TNode |
Remarks
TRAVERSAL VS VISIT
The word "traversal" in TreeTraversal<TEdge, TNode> and its derivations, is here used with
narrower scope than the word "visit" in IVisitStrategy<TNode, TVisitContext>.
- "Traversal" is used here as common class between DFS and BFS, as a visit strategy that starts from the root
of the tree and proceeds downwards, following edges and terminating when leafs are reached.
- "Visit" is used in a more general sense, as any algorithm which "touches" 0 or more nodes of the tree,
walking the tree in any possible way (up, down, sideways, ...).
Properties
| Improve this Doc View SourceChildrenSorter
The order of visit of the children. By default Children is returned as is, and no specific order is imposed to the sequence of (edge, node) couples, during the visit.
Declaration
public Func<TreeTraversalVisit<TEdge, TNode>, IEnumerable<KeyValuePair<TEdge, TNode>>> ChildrenSorter { get; set; }
Property Value
Type | Description |
---|---|
Func<TreeTraversalVisit<TEdge, TNode>, IEnumerable<KeyValuePair<TEdge, TNode>>> |
Remarks
Specifying a well-defined, deterministic order ensures that children are visited in a consistent and reproducible way across executions of the visit.
TraversalOrder
The traversal order between parent and its children, to be applied when visiting the tree. By default ParentFirst is applied, meaning that the parent node is visited before its children.
Declaration
public TreeTraversalOrder TraversalOrder { get; set; }
Property Value
Type | Description |
---|---|
TreeTraversalOrder |
Methods
| Improve this Doc View SourceVisit(TNode)
Lazily visits the structure of the provided node
, returning an enumerable of the
sequence of IRecImmDictIndexedTreeNode<TEdge, TNode> of the structure, in the order defined by
this IVisitStrategy<TNode, TVisitContext>.
Declaration
public abstract IEnumerable<TreeTraversalVisit<TEdge, TNode>> Visit(TNode node)
Parameters
Type | Name | Description |
---|---|---|
TNode | node | The node on where to start visit the structure. |
Returns
Type | Description |
---|---|
IEnumerable<TreeTraversalVisit<TEdge, TNode>> | A sequence emitting (node, visit context) couples, in the visit order defined by the visit strategy. |