A reproducible example:
Graph(1~>2, 2~>1, 2~>3, 3~>4, 4~>5, 5~>6, 6~>7, 7~>8, 8~>9, 9~>10).topologicalSort
// res: graph.CycleNodeOrTopologicalOrder = Left(9)
Graph(1~>2, 2~>1, 2~>3, 3~>4, 4~>5, 5~>6, 6~>7, 7~>8, 8~>9, 9~>10).topologicalSortByComponent.toList
// res: List[graph.CycleNodeOrTopologicalOrder] = List(Left(9))
val graph = Graph(1~>2, 2~>1, 2~>3, 3~>4, 4~>5, 5~>6, 6~>7, 7~>8, 8~>9, 9~>10)
graph.topologicalSort match {
case Left(nodeInCycle) => graph.findCycleContaining(nodeInCycle)
}
// res: Option[graph.Cycle] = None
A reproducible example: