Class CycleFinder<T>

java.lang.Object
com.yahoo.container.di.componentgraph.cycle.CycleFinder<T>

public class CycleFinder<T> extends Object

Applies the three-color algorithm to detect a cycle in a directed graph. If there are multiple cycles, this implementation only detects one of them and does not guarantee that the shortest cycle is found.

Author:
gjoranv
  • Constructor Details

    • CycleFinder

      public CycleFinder(Graph<T> graph)
  • Method Details

    • findCycle

      public List<T> findCycle()
      Returns a list of vertices constituting a cycle in the graph, or an empty list if no cycle was found. Only the first encountered cycle is returned.