Package com.jgalgo
Interface DFSIter
-
- All Superinterfaces:
IntIterator
,Iterator<Integer>
,PrimitiveIterator<Integer,IntConsumer>
,PrimitiveIterator.OfInt
public interface DFSIter extends IntIterator
Depth first search (DFS) iterator.The DFS iterator is used to iterate over the vertices of a graph is a depth first manner, namely it explore as far as possible along each branch before backtracking. The iterator will visit every vertex \(v\) for which there is a path from the source(s) to \(v\). Each such vertex will be visited exactly once.
The graph should not be modified during the DFS iteration.
Graph g = ...; int sourceVertex = ...; for (DFSIter iter = DFSIter.newInstance(g, sourceVertex); iter.hasNext();) { int v = iter.nextInt(); IntList edgePath = iter.edgePath(); System.out.println("Reached vertex " + v + " using the edges: " + edgePath); }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.PrimitiveIterator
PrimitiveIterator.OfDouble, PrimitiveIterator.OfInt, PrimitiveIterator.OfLong
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description IntList
edgePath()
Get the path from the source to the last vertex returned bynextInt()
.boolean
hasNext()
Check whether there is more vertices to iterate over.static DFSIter
newInstance(Graph g, int source)
Create a DFS iterator rooted at some source vertex.int
nextInt()
Advance the iterator and return a vertex that was not visited by the iterator yet.-
Methods inherited from interface it.unimi.dsi.fastutil.ints.IntIterator
forEachRemaining, forEachRemaining, next, skip
-
Methods inherited from interface java.util.PrimitiveIterator.OfInt
forEachRemaining
-
-
-
-
Method Detail
-
newInstance
static DFSIter newInstance(Graph g, int source)
Create a DFS iterator rooted at some source vertex.- Parameters:
g
- a graphsource
- a vertex in the graph from which the search will start from- Returns:
- a DFS iterator that iterate over the vertices of the graph
-
hasNext
boolean hasNext()
Check whether there is more vertices to iterate over.
-
nextInt
int nextInt()
Advance the iterator and return a vertex that was not visited by the iterator yet.- Specified by:
nextInt
in interfaceIntIterator
- Specified by:
nextInt
in interfacePrimitiveIterator.OfInt
-
edgePath
IntList edgePath()
Get the path from the source to the last vertex returned bynextInt()
.The behavior is undefined if
nextInt()
was not called yet.- Returns:
- list of edges forming a path from the source to the last vertex returned by
nextInt()
. The returned list should not be modified by the user.
-
-