/** Populates a collection with the nodes reachable from a given node. */ public static <V, E extends DefaultEdge> void reachable(Collection<V> list, final DirectedGraph<V, E> graph, final V start) { buildListRecurse(list, new HashSet<>(), graph, start); }
/** Populates a collection with the nodes reachable from a given node. */ public static <V, E extends DefaultEdge> void reachable(Collection<V> list, final DirectedGraph<V, E> graph, final V start) { buildListRecurse(list, new HashSet<>(), graph, start); }
private static <V, E extends DefaultEdge> List<V> buildList( DirectedGraph<V, E> graph, V start) { final List<V> list = new ArrayList<>(); buildListRecurse(list, new HashSet<>(), graph, start); return list; }
private static <V, E extends DefaultEdge> List<V> buildList( DirectedGraph<V, E> graph, V start) { final List<V> list = new ArrayList<>(); buildListRecurse(list, new HashSet<>(), graph, start); return list; }
private static <V, E extends DefaultEdge> void buildListRecurse( Collection<V> list, Set<V> activeVertices, DirectedGraph<V, E> graph, V start) { if (!activeVertices.add(start)) { return; } list.add(start); List<E> edges = graph.getOutwardEdges(start); for (E edge : edges) { //noinspection unchecked buildListRecurse(list, activeVertices, graph, (V) edge.target); } activeVertices.remove(start); }
private static <V, E extends DefaultEdge> void buildListRecurse( Collection<V> list, Set<V> activeVertices, DirectedGraph<V, E> graph, V start) { if (!activeVertices.add(start)) { return; } list.add(start); List<E> edges = graph.getOutwardEdges(start); for (E edge : edges) { //noinspection unchecked buildListRecurse(list, activeVertices, graph, (V) edge.target); } activeVertices.remove(start); }