Table of Contents

Class TreeExtensions

Namespace
CriusNyx.Util
Assembly
CriusNyxUtil.dll

Extensions to work with trees.

public static class TreeExtensions
Inheritance
TreeExtensions
Inherited Members

Methods

TraverseFlat<T>(T)

Convert tree to a list of nodes in Bredth First Order. Returns a tuples of nodes with their depth.

public static IEnumerable<(T node, int depth)> TraverseFlat<T>(this T node) where T : ITree<T>

Parameters

node T

Returns

IEnumerable<(T value, int index)>

Type Parameters

T

TraverseFlat<T>(T, Func<T, IEnumerable<T>>, int)

Convert tree to a list of nodes in Breadth First Order using getChildren to find the nodes children. Returns a tuples of nodes with their depth.

public static IEnumerable<(T node, int depth)> TraverseFlat<T>(this T node, Func<T, IEnumerable<T>> getChildren, int depth = 0)

Parameters

node T
getChildren Func<T, IEnumerable<T>>
depth int

Returns

IEnumerable<(T value, int index)>

Type Parameters

T

Traverse<T>(T, Action<T, int>)

Visit each node, with it's depth, in the tree in a breadth first order.

public static void Traverse<T>(this T node, Action<T, int> visitor) where T : ITree<T>

Parameters

node T
visitor Action<T, int>

Type Parameters

T

Traverse<T>(T, Action<T, int>, Func<T, IEnumerable<T>>)

Visit each node, with it's depth, in a tree using the getChildren function to find children.

public static void Traverse<T>(this T node, Action<T, int> visitor, Func<T, IEnumerable<T>> getChildren)

Parameters

node T
visitor Action<T, int>
getChildren Func<T, IEnumerable<T>>

Type Parameters

T

Traverse<T>(T, Action<T>)

Visit each node in the tree in breadth first order.

public static void Traverse<T>(this T node, Action<T> visitor) where T : ITree<T>

Parameters

node T
visitor Action<T>

Type Parameters

T

Traverse<T>(T, Action<T>, Func<T, IEnumerable<T>>)

Visit each node in a tree using the getChildren function to find children.

public static void Traverse<T>(this T node, Action<T> visitor, Func<T, IEnumerable<T>> getChildren)

Parameters

node T
visitor Action<T>
getChildren Func<T, IEnumerable<T>>

Type Parameters

T