/** * Helper mode for {@link #getSortedNodes()}, via {@link TopologicalSortSupplier}. This method * does a depth-first traversal of the nodes, adding each to the {@code visited} set when it is * left. This results in {@code visited} being a topological sort. * * @param visited The set of nodes seen so far. */ private void sortVisit(LinkedHashSet<DAGNode<V,E>> visited) { if (!visited.contains(this)) { for (DAGEdge<V,E> nbr: outgoingEdges) { nbr.getTail().sortVisit(visited); } // neighbors won't have added this, or we have an impossible cycle assert !visited.contains(this); visited.add(this); } }