26 using System.Collections.Generic;
40 private DisjointSet<Node> nodeGroups;
41 private int unionCount;
46 nodeGroups =
new DisjointSet<Node>();
63 var x = nodeGroups.WhereIs(u);
64 var y = nodeGroups.WhereIs(v);
65 if (x.Equals(y))
return x.Representative;
67 return nodeGroups.Union(x, y).Representative;
75 return Merge(graph.
U(arc), graph.
V(arc));
80 return nodeGroups.WhereIs(graph.
U(arc)).Representative;
85 return nodeGroups.WhereIs(graph.
V(arc)).Representative;
93 public IEnumerable<Node>
Nodes()
95 foreach (var node
in graph.
Nodes())
96 if (nodeGroups.WhereIs(node).Representative == node) yield
return node;
101 return graph.
Arcs(filter);
106 DisjointSetSet<Node> x = nodeGroups.WhereIs(u);
107 foreach (var node
in nodeGroups.Elements(x))
109 foreach (var arc
in graph.
Arcs(node, filter))
111 bool loop = (
U(arc) ==
V(arc));
113 if (!loop || !(filter ==
ArcFilter.All ||
IsEdge(arc)) || graph.
U(arc) == node)
121 foreach (var arc
in Arcs(u, filter))
122 if (this.Other(arc, u) == v) yield
return arc;
137 return Arcs(u, filter).Count();
142 return Arcs(u, v, filter).Count();
147 return node == nodeGroups.WhereIs(node).Representative;