MultiwayTree 1.1.0
dotnet add package MultiwayTree --version 1.1.0
NuGet\Install-Package MultiwayTree -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MultiwayTree" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MultiwayTree --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MultiwayTree, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MultiwayTree as a Cake Addin #addin nuget:?package=MultiwayTree&version=1.1.0 // Install MultiwayTree as a Cake Tool #tool nuget:?package=MultiwayTree&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MultiwayTree
Summary
This repository aims to provide a simple, concise, flexible, and well-tested multiway tree nuget package for dotnet core.
Background
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
Usage
- Install the nuget package from nuget.org with your favorite package manager.
- Instantiate a
MultiwayTree<T>
whereT
is your desired tree node data Type.- e.g.
new MultiwayTree<int>(0)
will have aData
property of Typeint
with value0
.
- e.g.
- Add child nodes to your tree.
- If
myTree
is aMultiwayTree<int>
,myTree.AddChild(1)
ormyTree.AddChild(new MultiwayTree<int>(1))
will have the same effect. - Note:
T
must be the same Type for all nodes of a tree i.e. ifmyTree
is aMultiwayTree<int>
, thenmyTree.AddChild("this is a string")
is not possible.
- If
- Instantiate your tree traverser.
- Option 1: Instantiate a
GenericMultiwayTreeTraverser
.- Best for simple node visitation logic.
- Expects two type parameters:
- the Type of
Data
in the tree(s) you'll be traversing, and - the Type of the return value of your node visitation function.
- the Type of
- Expects a single constructor parameter: An async delegate function defining what it means to visit a node. Lambda syntax is convenient for this e.g.
var myTraverser = new GenericMultiwayTreeTraverser<int, string>( async (dataInt, cumulativeResultString) => { return (cumulativeResultString ?? string.Empty) + dataInt.ToString(); } );
- Note: The node visitation function expects two parameters:
- the
Data
property value of the current node, and - the return value from the most recent node visitation function invocation. This will be null when you visit the first node if
T
is nullable.
- the
- Note: The node visitation function expects two parameters:
- Option 2: Implement your own tree traversal class.
- Best for more complex node visitation logic, and works well with IoC pattern.
- Extend
AbstractMultiwayTreeTraverser
e.g.
public class MyTreeTraverser : AbstractMultiwayTreeTraverser<int, string>
- Override and implement
VisitNodeAsync
with whatever logic you want.VisitNodeAsync
must return aNodeVisitResult
which has 2 properties:- a
TValue
Value
whereTValue
is the second Type parameter you set when extendingAbstractMultiwayTreeTraverser
, and - a
bool
ContinueTraversing
which is only relevant when your traversal type isTraversalType.LevelOrderSearch
(see below).
- a
- Option 1: Instantiate a
- Traverse your tree.
- 4 traversal types are provided via an
enum
:TraversalType.LevelOrder
TraversalType.PostOrder
TraversalType.PreOrder
TraversalType.LevelOrderSearch
- All traversal types except
LevelOrderSearch
will visit every node in the tree.LevelOrderSearch
will stop traversing the tree when theContinueTraversing
property of theVisitNodeResult
returned from visiting the most recent node isfalse
. - Example:
var result = await myTraverser.TraverseAsync(myTree, TraversalType.PreOrder)
- 4 traversal types are provided via an
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.