TTK
Loading...
Searching...
No Matches
home
julien
Pro
git
github
thomas
ttk-dani
core
base
ripsPersistenceDiagram
RipsPersistenceDiagramUtils.cpp
Go to the documentation of this file.
1
#include <
RipsPersistenceDiagramUtils.h
>
2
3
ttk::rpd::UnionFind::UnionFind
(
unsigned
n) {
4
parent_.resize(n);
5
rank_.resize(n, 0);
6
for
(
unsigned
i = 0; i < n; i++)
7
parent_[i] = i;
8
}
9
10
int
ttk::rpd::UnionFind::find
(
int
x) {
11
if
(parent_[x] == x)
12
return
x;
13
return
parent_[x] =
find
(parent_[x]);
// path compression
14
}
15
16
void
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
31
int
ttk::rpd::UnionFind::mergeRet
(
int
x,
int
y) {
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
47
bool
ttk::rpd::UnionFind::isRoot
(
int
x)
const
{
48
return
parent_[x] == x;
49
}
RipsPersistenceDiagramUtils.h
ttk::rpd::UnionFind::mergeRet
int mergeRet(int x, int y)
Definition
RipsPersistenceDiagramUtils.cpp:31
ttk::rpd::UnionFind::find
int find(int x)
Definition
RipsPersistenceDiagramUtils.cpp:10
ttk::rpd::UnionFind::isRoot
bool isRoot(int x) const
Definition
RipsPersistenceDiagramUtils.cpp:47
ttk::rpd::UnionFind::UnionFind
UnionFind(unsigned n)
Definition
RipsPersistenceDiagramUtils.cpp:3
ttk::rpd::UnionFind::merge
void merge(int x, int y)
Definition
RipsPersistenceDiagramUtils.cpp:16
Generated on Fri Apr 10 2026 10:02:08 for TTK by
1.13.2