We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f5dfb52 commit 9f0c4bfCopy full SHA for 9f0c4bf
src/tdamapper/utils/unionfind.py
@@ -5,10 +5,15 @@ def __init__(self, X):
5
self.__size = {x: 1 for x in X}
6
7
def find(self, x):
8
- y = x
9
- while y != self.__parent[y]:
10
- y = self.__parent[y]
11
- return y
+ root = x
+ while root != self.__parent[root]:
+ root = self.__parent[root]
+ tmp = x
12
+ while tmp != root:
13
+ parent = self.__parent[tmp]
14
+ self.__parent[tmp] = root
15
+ tmp = parent
16
+ return root
17
18
def union(self, x, y):
19
x, y = self.find(x), self.find(y)
0 commit comments