Created
May 15, 2013 10:19
-
-
Save anonymous/5582985 to your computer and use it in GitHub Desktop.
Scala Cycle Detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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