| 106 | } |
| 107 | |
| 108 | private void collectSCC(N node, Deque<N> stack, Set<N> inStack, Graph<N> graph) { |
| 109 | List<N> scc = new ArrayList<>(); |
| 110 | N v2; |
| 111 | do { |
| 112 | v2 = stack.pop(); |
| 113 | inStack.remove(v2); |
| 114 | scc.add(v2); |
| 115 | } while (node != v2); |
| 116 | // Reverse SCC so that the nodes connected to predecessors |
| 117 | // (outside the SCC) will be listed ahead. |
| 118 | Collections.reverse(scc); |
| 119 | componentList.add(scc); |
| 120 | if (scc.size() > 1) { |
| 121 | trueComponentList.add(scc); |
| 122 | } else { |
| 123 | N n = scc.get(0); |
| 124 | if (graph.hasEdge(n, n)) { |
| 125 | trueComponentList.add(scc); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Validates whether the number of nodes in all components is |