Exemple #1
0
 private static <N> void doDfs(
     @NotNull N current,
     @NotNull Neighbors<N> neighbors,
     @NotNull Visited<N> visited,
     @NotNull NodeHandler<N, ?> handler) {
   if (!visited.checkAndMarkVisited(current)) {
     return;
   }
   handler.beforeChildren(current);
   for (N neighbor : neighbors.getNeighbors(current)) {
     doDfs(neighbor, neighbors, visited, handler);
   }
   handler.afterChildren(current);
 }
Exemple #2
0
 public static <N, R> R dfsFromNode(
     @NotNull N node,
     @NotNull Neighbors<N> neighbors,
     @NotNull Visited<N> visited,
     @NotNull NodeHandler<N, R> handler) {
   doDfs(node, neighbors, visited, handler);
   return handler.result();
 }
Exemple #3
0
 public static <N, R> R dfs(
     @NotNull Collection<N> nodes,
     @NotNull Neighbors<N> neighbors,
     @NotNull Visited<N> visited,
     @NotNull NodeHandler<N, R> handler) {
   for (N node : nodes) {
     doDfs(node, neighbors, visited, handler);
   }
   return handler.result();
 }