Class BFSIterator

java.lang.Object
org.graph4j.traversal.BFSIterator
All Implemented Interfaces:
Iterator<SearchNode>

public class BFSIterator extends Object implements Iterator<SearchNode>
A breadth first search (BFS) iterator over the vertices of the graph.
Author:
Cristian Frăsinaru
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    boolean
     
    int
    Returns the maximum level in the search tree, identified so far by the iterator.
     
    int
    Returns the number of connected components identified so far by the iterator.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining, remove
  • Constructor Details

    • BFSIterator

      public BFSIterator(Graph graph)
      Creates an iterator starting with the first vertex of the graph (the one at index 0)
      Parameters:
      graph - the input graph.
    • BFSIterator

      public BFSIterator(Graph graph, int start)
      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

      public 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. In case of undirected graphs, the reverse argument is ignored.
      Parameters:
      graph - the input graph.
      start - the start vertex number.
      forbiddenVertices - vertices that are not allowed in the path; can be null if there are no forbidden vertices.
      reverse - if true iteration 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:
      hasNext in interface Iterator<SearchNode>
    • next

      public SearchNode next()
      Specified by:
      next in interface Iterator<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.