A helper class for working with trees.

Static methods

staticmap<A, B> (treeNode:TreeNode<A>, create:B ‑> A ‑> B, ?parent:B):B

Map a given treeNode to a new tree structure.

Example:

class CustomNode {
	public var parent:CustomNode;
	public var children = new Array<CustomNode>();
	public var value:String;
	public function new(parent:CustomNode, value:String) {
		this.value = value;
		this.parent = parent;
		if (parent != null) parent.children.push(this);
	}
	public function print(depth = 0, initiator = true) {
		trace(StringTools.rpad("", "\t", depth) + value);
		for (i in children) i.print(depth + 1, false);
	}
}

...

// create a random tree
var tree:TreeNode<String> = TreeTools.randomTree((depth:Int, childIndex:Int) -> depth + "." + childIndex, 3, 1, 5);
trace(tree.toString());

// map to a tree of CustomNode objects
var customNodeTree = map(tree, (parent:CustomNode, value:String) -> new CustomNode(parent, value));
customNodeTree.print();

@:value({ indent : "\t" })staticofIndentedList<T> (list:String, getValue:String ‑> T, indent:String = "\t"):TreeNode<T>

Creates a tree structure from an indented list.

staticofXml (string:String):TreeNode<XmlNode>

Creates a tree structure from an XML string.

staticrandomTree<T> (getValue:Int ‑> Int ‑> T, maxDepth:Int, minChildCount:Int, maxChildCount:Int, ?rand:Void ‑> Float):TreeNode<T>

Creates a random tree structure.

getValue() is called for every tree node; the signature is: getValue(currentDepth, currentChildIndex):T