Refactor out queueing of parents
@@ -80,7 +80,16 @@ public class DifferentiableChecker {
}
if (shouldAddParents.test(visiting)) {
- Collection<Vertex> nextVertices = visiting.getParents();
+ queueUnvisitedParents(visiting, queue, visited);
+ }
+ }
+
+ successfullyVisitedConsumer.accept(visited);
+ return true;
+ }
+
+ private static void queueUnvisitedParents(Vertex vertex, Queue<Vertex> queue, Set<Vertex> visited) {
+ Collection<Vertex> nextVertices = vertex.getParents();
for (Vertex next : nextVertices) {
if (!visited.contains(next)) {
queue.offer(next);
@@ -88,10 +97,6 @@ public class DifferentiableChecker {
}
}
}
- }
- successfullyVisitedConsumer.accept(visited);
- return true;
- }
private static boolean isNonDiffableAndNotConstant(Vertex vertex, Set<Vertex> constantValueVerticesCache) {
return !vertex.isDifferentiable() && !isVertexValueConstant(Collections.singletonList(vertex), constantValueVerticesCache);
