MCPcopy Create free account
hub / github.com/ActiveState/code / Union

Function Union

recipes/Python/577225_UnionFind/recipe-577225.py:16–25  ·  view source on GitHub ↗
(x, y)

Source from the content-addressed store, hash-verified

14 x.rank = 0
15
16def Union(x, y):
17 xRoot = Find(x)
18 yRoot = Find(y)
19 if xRoot.rank > yRoot.rank:
20 yRoot.parent = xRoot
21 elif xRoot.rank < yRoot.rank:
22 xRoot.parent = yRoot
23 elif xRoot != yRoot: # Unless x and y are already in same set, merge them
24 yRoot.parent = xRoot
25 xRoot.rank = xRoot.rank + 1
26
27def Find(x):
28 if x.parent == x:

Callers 1

recipe-577225.pyFile · 0.70

Calls 1

FindFunction · 0.85

Tested by

no test coverage detected