Constructs a new graph with the given value to set
Creates a new graph without associating any value with itself
Appends another graph node to the array of children of this node's
Performs a depth first search on the graph by firstly calling the TouchStratergy on the current node and then iterating over all of its children and only recursing on each of them if the InclusionStratergy allows it.
This will attempt to find the graph node which contains the provided value.
Obtains the value associated with this graph node
Returns the number of children attached to this node
Returns the element of the child at the given index.
Returns the value of the child node at the provided index
Returns a slice of the requested type. This is either Graph!(T) or T itself, therefore returning an array of either
Returns an array of all the childrens' associated values
Removes a given graph node from th array of children of thie node's
Sets the graph node's associated value
Returns a string representation of this node and its value
Returns the number of children attached to this node
Test out usage of the Graph!(T)
Graph!(string) treeOfStrings = new Graph!(string)("Top"); Graph!(string) subtree_1 = new Graph!(string)("1"); Graph!(string) subtree_2 = new Graph!(string)("2"); Graph!(string) subtree_3 = new Graph!(string)("3"); treeOfStrings.appendNode(subtree_1); treeOfStrings.appendNode(subtree_2); treeOfStrings.appendNode(subtree_3); assert(treeOfStrings.opIndex!(Graph!(string))(0) == subtree_1); assert(treeOfStrings.opIndex!(Graph!(string))(1) == subtree_2); assert(treeOfStrings.opIndex!(Graph!(string))(2) == subtree_3); assert(treeOfStrings[0] == subtree_1.getValue()); assert(treeOfStrings[1] == subtree_2.getValue()); assert(treeOfStrings[2] == subtree_3.getValue()); assert(treeOfStrings.opDollar() == 3); Optional!(Graph!(string)) match_opt = treeOfStrings.findByValue("2"); assert(match_opt.isPresent()); assert(match_opt.get() is subtree_2); InclusionStratergy!(string) strat = toDelegate(&Always!(string)); TouchStratergy!(string) touch = toDelegate(&DebugTouch!(string)); string[] result = treeOfStrings.dfs(strat, touch); writeln("dfs: ", result); assert(result[0] == "1"); assert(result[1] == "2"); assert(result[2] == "3"); assert(result[3] == "Top"); auto i = treeOfStrings.opSlice!(Graph!(string))(); writeln("Siblings: ", i); assert(i[0] == subtree_1); assert(i[1] == subtree_2); assert(i[2] == subtree_3); auto p = treeOfStrings.opSlice!(string)(); writeln("Siblings (vals): ", p); assert(p == treeOfStrings[]); assert(treeOfStrings.removeNode(subtree_1)); assert(!treeOfStrings.removeNode(subtree_1));
VisitationTree
A graph of nodes.
These nodes are comprised of two components. The first of which is their associated value of type T, then the second are their children nodes (if any). The latter are of type Graph!(T) and therefore when constructing one such node it can also be added as a child of another node, therefore allowing you to build your graph as you see fit.
Some notable functionality, other than the obvious, is the pluggable dfs method which let's you perform a recursive search on the graph, parameterized by two stratergies. The first is the so-called TouchStratergy which specifies the function to be called on the current node when dfs is called on it - this is the first thing that is done. The other parameter is the VisitationStratergy which is a predicate that will be called BEFORE entering the dfs (recursing) of a candidate child node. With this things like trees can be built or rather _derived_ from a graph. This is infact what the visitation tree type does.