guava/src/com/google/common/graph/Traverser.java
public static <N> Traverser<N> forGraph(SuccessorsFunction<N> graph) {
    checkNotNull(graph);
    return new GraphTraverser<>(graph);
  }
public static <N> Traverser<N> forGraph(SuccessorsFunction<N> graph) {
    checkNotNull(graph);
    return new GraphTraverser<>(graph);
  }
public static < N > Traverser < N > forGraph ( SuccessorsFunction < N > graph ) { checkNotNull ( graph ) ; return new GraphTraverser <> ( graph ) ; }
Creates a new traverser for the given general {@code graph}.

<p>Traversers created using this method are guaranteed to visit each node reachable from the
start node(s) at most once.

<p>If you know that no node in {@code graph} is reachable by more than one path from the start
node(s), consider using {@link #forTree(SuccessorsFunction)} instead.

<p><b>Performance notes</b>

<ul>
<li>Traversals require <i>O(n)</i> time (where <i>n</i> is the number of nodes reachable from
the start node), assuming that the node objects have <i>O(1)</i> {@code equals()} and
{@code hashCode()} implementations. (See the <a
href="https://github.com/google/guava/wiki/GraphsExplained#elements-must-be-useable-as-map-keys">
notes on element objects</a> for more information.)
<li>While traversing, the traverser will use <i>O(n)</i> space (where <i>n</i> is the number
of nodes that have thus far been visited), plus <i>O(H)</i> space (where <i>H</i> is the
number of nodes that have been seen but not yet visited, that is, the "horizon").
</ul>

@param graph {@link SuccessorsFunction} representing a general graph that may have cycles.
Creates a new traverser for the given general { @code graph } .