Class BfsDfsVertexSpliterator<V>

Type Parameters:
V - the vertex data type
All Implemented Interfaces:
Spliterator<V>, BareEnumerator<V>, Enumerator<V>

public class BfsDfsVertexSpliterator<V> extends AbstractEnumerator<V>
Enumerates vertices in a graph starting from a root vertex in breadth-first-order or in depth-first-order.

References:

Robert Sedgewick, Kevin Wayne. (2011)
Algorithms, 4th Edition. Chapter 4. Algorithm 4.1 Depth-First Search; Algorithm 4.2. Breadth-First Search. math.cmu.edu
Author:
Werner Randelshofer
  • Constructor Details

    • BfsDfsVertexSpliterator

      public BfsDfsVertexSpliterator(@NonNull Function<V,Iterable<V>> nextFunction, @NonNull V root, boolean dfs)
      Creates a new instance.
      Parameters:
      nextFunction - a function that returns the next vertices for a given vertex
      root - the root vertex
      dfs - whether to enumerate depth-first instead of breadth-first
    • BfsDfsVertexSpliterator

      public BfsDfsVertexSpliterator(@NonNull Function<V,Iterable<V>> nextFunction, @NonNull V root, @NonNull AddToSet<V> visited, boolean dfs)
      Creates a new instance.
      Parameters:
      nextFunction - a function that returns the next vertices for a given vertex
      root - the root vertex
      visited - a function that adds a provided vertex to a set, and returns true if the vertex was not in the set. If the graph is known to be a tree, the function can always return true.
      dfs - whether to enumerate depth-first instead of breadth-first
  • Method Details

    • moveNext

      public boolean moveNext()