Package Description
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Jun 28, 2023
$ dotnet add package MultiwayTreeThis repository aims to provide a simple, concise, flexible, and well-tested multiway tree nuget package for dotnet core.
A multiway tree is a tree that can have more than two children. A multiway tree of order k (or an k-way or k-ary tree) is one in which a tree can have k children. Learn more about multiway trees
MultiwayTree<T> where T is your desired tree node data Type.
new MultiwayTree<int>(0) will have a Data property of Type int with value 0.myTree is a MultiwayTree<int>, myTree.AddChild(1) or myTree.AddChild(new MultiwayTree<int>(1)) will have the same effect.T must be the same Type for all nodes of a tree i.e. if myTree is a MultiwayTree<int>, then myTree.AddChild("this is a string") is not possible.GenericMultiwayTreeTraverser.
Data in the tree(s) you'll be traversing, andvar myTraverser = new GenericMultiwayTreeTraverser<int, string>(
async (dataInt, cumulativeResultString) => {
return (cumulativeResultString ?? string.Empty)
+ dataInt.ToString();
}
);
Data property value of the current node, andT is nullable.AbstractMultiwayTreeTraverser e.g. public class MyTreeTraverser : AbstractMultiwayTreeTraverser<int, string>
VisitNodeAsync with whatever logic you want.
VisitNodeAsync must return a NodeVisitResult which has 2 properties:
TValue Value where TValue is the second Type parameter you set when extending AbstractMultiwayTreeTraverser, andbool ContinueTraversing which is only relevant when your traversal type is TraversalType.LevelOrderSearch (see below).enum:
TraversalType.LevelOrderTraversalType.PostOrderTraversalType.PreOrderTraversalType.LevelOrderSearchLevelOrderSearch will visit every node in the tree. LevelOrderSearch will stop traversing the tree when the ContinueTraversing property of the VisitNodeResult returned from visiting the most recent node is false. var result = await myTraverser.TraverseAsync(myTree, TraversalType.PreOrder)