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

PrintTree<T>(T, Func<T, IEnumerable<T>>, Func<T, string>, int)

Print all the elements in a tree.

public static string PrintTree<T>(this T element, Func<T, IEnumerable<T>> getChildren, Func<T, string> printer = null, int lineLength = -1)

Parameters

element T
getChildren Func<T, IEnumerable<T>>
printer Func<T, string>
lineLength int

Returns

string

Type Parameters

T

PrintTree<T>(T, Func<T, string>, int)

Print all the elements in a tree.

public static string PrintTree<T>(this T tree, Func<T, string> printer = null, int lineLength = -1) where T : ITree<T>

Parameters

tree T
printer Func<T, string>
lineLength int

Returns

string

Type Parameters

T

TraverseFlat<T>(T)

Convert tree to a list of nodes in breadth 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