private bool CycleFromCurrentNode(BindingNode node, BindingNode previousNode, HashSet <BindingNode> unvisited, HashSet <BindingNode> seen) { /* * Recursively checks whether the current node will lead to a cycle */ if (seen.Contains(node)) { return(true); } else { unvisited.Remove(node); seen.Add(node); bool cycle = false; foreach (BindingNode child in node.AdjacentNodes .Where(child => !child.Equals(previousNode))) // Prevent the traversal from looping back over two-way bindings { cycle = cycle || CycleFromCurrentNode(child, node, unvisited, seen); } return(cycle); } }
public void Bind(BindPoint first, BindPoint second) { /* * Link the two nodes in one direction */ BindingNode firstNode = FindNodeForPoint(first); BindingNode secondNode = FindNodeForPoint(second); firstNode.AddEdgeTo(secondNode); }
public void RemoveBindings(BindPoint[] sources, BindPoint[] destinations) { /* * Remove all bindings between the sources and the destinations */ foreach (BindPoint source in sources) { BindingNode node = FindNodeForPoint(source); node.AdjacentNodes.RemoveAll((BindingNode n) => destinations.Contains(n.Vertex)); } }
public void AddEdgeTo(BindingNode other) { AdjacentNodes.Add(other); }
private bool CycleFromCurrentNode(BindingNode node, BindingNode previousNode, HashSet<BindingNode> unvisited, HashSet<BindingNode> seen) { /* * Recursively checks whether the current node will lead to a cycle */ if (seen.Contains(node)) return true; else { unvisited.Remove(node); seen.Add(node); bool cycle = false; foreach (BindingNode child in node.AdjacentNodes .Where(child => !child.Equals(previousNode))) // Prevent the traversal from looping back over two-way bindings { cycle = cycle || CycleFromCurrentNode(child, node, unvisited, seen); } return cycle; } }