moaxcp / graph-dsl

A groovy dsl for creating and traversing graphs.
https://moaxcp.github.io/graph-dsl/
MIT License
27 stars 6 forks source link

Depth First Search Methods #58

Closed moaxcp closed 6 years ago

moaxcp commented 7 years ago

In all of these methods the graph is the delegate and 'it' in each closure is the vertex. This allows other methods in the graph to be used during traversal. For instance a user can get the inEdges or outEdges for the vertex in a DirecedGraph. This can be useful for finding vertices with certain input or output while traversing the graph.

Unlike breadth first search, depth first search has different orders: pre-order, in-order, post-order, and reverse post-order. This means there are 4 versions of each higher-order method (each, find, findAll, inject, collect).

The default methods for graph will use dfs preorder methods. This means each higher-order methd (find, findAll, inject, and collect) in graph will be aliases to the dfs preorder methods.

For every higher order method there will be the default which aliases to PreOrder and there will be methods for each ordering. For example each will have each, eachPreOrder, eachInOrder, eachPostOrder, and eachReversePostOrder. The pattern is each${order}(...).

each methods

find methods

findAll methods

inject methods

collect methods

traverseEdges

The above methods need a method that tells them which edges to follow during a traversal. In the past this was called adjacentEdges but that name doesn't fit well. This method needs to be modified when DirectedGraphPlugin is applied to only return outEdges. This method will be used in breadth first search methods as well.