Skip to content

Instantly share code, notes, and snippets.

Created May 15, 2013 10:19
Show Gist options
  • Save anonymous/5582985 to your computer and use it in GitHub Desktop.
Save anonymous/5582985 to your computer and use it in GitHub Desktop.
Scala Cycle Detection
def isCyclic(graphManager: PricingGraphManager) = graphManager.nodes.exists(hasCycle(graphManager, _, Seq()))
private def hasCycle(graphManager: PricingGraphManager, node:PricingGraphNode, visitedNodes:Seq[PricingGraphNode]) : Boolean =
if (visitedNodes.contains(node)) true else node.children.exists(hasCycle(graphManager, _, node +: visitedNodes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment