Package org.graph4j.traversal
Class BFSIterator
java.lang.Object
org.graph4j.traversal.BFSIterator
- All Implemented Interfaces:
Iterator<SearchNode>
A breadth first search (BFS) iterator over the vertices of the graph.
- Author:
- Cristian Frăsinaru
-
Constructor Summary
ConstructorsConstructorDescriptionBFSIterator(Graph graph) Creates an iterator starting with the first vertex of the graph (the one at index 0)BFSIterator(Graph graph, int start) Creates an iterator starting with the specified vertex.BFSIterator(Graph graph, int start, int[] forbiddenVertices, boolean reverse) Creates an iterator starting with the specified vertex, traversing a directed graph either in the direction of the arcs, or in reversed direction. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
BFSIterator
Creates an iterator starting with the first vertex of the graph (the one at index 0)- Parameters:
graph- the input graph.
-
BFSIterator
Creates an iterator starting with the specified vertex.- Parameters:
graph- the input graph.start- the start vertex number.- Throws:
InvalidVertexException- if the graph does not contain the start vertex.
-
BFSIterator
Creates an iterator starting with the specified vertex, traversing a directed graph either in the direction of the arcs, or in reversed direction. In case of undirected graphs, thereverseargument is ignored.- Parameters:
graph- the input graph.start- the start vertex number.forbiddenVertices- vertices that are not allowed in the path; can benullif there are no forbidden vertices.reverse- iftrueiteration will pe performed on the reversed graph.- Throws:
InvalidVertexException- if the graph does not contain the start vertex.
-
-
Method Details
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<SearchNode>
-
next
- Specified by:
nextin interfaceIterator<SearchNode>
-
numComponents
public int numComponents()Returns the number of connected components identified so far by the iterator.- Returns:
- the number of connected components.
-
maxLevel
public int maxLevel()Returns the maximum level in the search tree, identified so far by the iterator. The root of the search tree is considered at level 0.- Returns:
- the maximum level in the search tree.
-