TTK
Loading...
Searching...
No Matches
RipsPersistenceDiagramUtils.cpp
Go to the documentation of this file.
2
4 parent_.resize(n);
5 rank_.resize(n, 0);
6 for(unsigned i = 0; i < n; i++)
7 parent_[i] = i;
8}
9
11 if(parent_[x] == x)
12 return x;
13 return parent_[x] = find(parent_[x]); // path compression
14}
15
16void ttk::rpd::UnionFind::merge(int x, int y) {
17 const int rootX = find(x);
18 const int rootY = find(y);
19 if(rootX != rootY) {
20 if(rank_[rootX] > rank_[rootY])
21 parent_[rootY] = rootX;
22 else if(rank_[rootX] < rank_[rootY])
23 parent_[rootX] = rootY;
24 else {
25 parent_[rootY] = rootX;
26 rank_[rootX]++;
27 }
28 }
29}
30
32 const int rootX = find(x);
33 const int rootY = find(y);
34 if(rootX != rootY) {
35 if(rank_[rootX] > rank_[rootY])
36 return parent_[rootY] = rootX;
37 else if(rank_[rootX] < rank_[rootY])
38 return parent_[rootX] = rootY;
39 else {
40 rank_[rootX]++;
41 return parent_[rootY] = rootX;
42 }
43 }
44 return rootX;
45}
46
47bool ttk::rpd::UnionFind::isRoot(int x) const {
48 return parent_[x] == x;
49}