Blender
V4.3
intern
cycles
util
disjoint_set.h
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#ifndef __UTIL_DISJOINT_SET_H__
6
#define __UTIL_DISJOINT_SET_H__
7
8
#include "
util/array.h
"
9
#include <utility>
10
11
CCL_NAMESPACE_BEGIN
12
13
class
DisjointSet
{
14
private
:
15
array<size_t>
parents;
16
array<size_t>
ranks;
17
18
public
:
19
DisjointSet
(
size_t
size
) : parents(
size
), ranks(
size
)
20
{
21
for
(
size_t
i = 0; i <
size
; i++) {
22
parents[i] = i;
23
ranks[i] = 0;
24
}
25
}
26
27
size_t
find
(
size_t
x
)
28
{
29
size_t
root =
x
;
30
while
(parents[root] != root) {
31
root = parents[root];
32
}
33
while
(parents[
x
] != root) {
34
size_t
parent = parents[
x
];
35
parents[
x
] = root;
36
x
= parent;
37
}
38
return
root;
39
}
40
41
void
join
(
size_t
x
,
size_t
y
)
42
{
43
size_t
x_root =
find
(
x
);
44
size_t
y_root =
find
(
y
);
45
46
if
(x_root == y_root) {
47
return
;
48
}
49
50
if
(ranks[x_root] < ranks[y_root]) {
51
std::swap(x_root, y_root);
52
}
53
parents[y_root] = x_root;
54
55
if
(ranks[x_root] == ranks[y_root]) {
56
ranks[x_root]++;
57
}
58
}
59
};
60
61
CCL_NAMESPACE_END
62
63
#endif
/* __UTIL_DISJOINT_SET_H__ */
x
x
Definition
BLI_expr_pylike_eval_test.cc:345
size
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition
btDbvt.cpp:52
DisjointSet::join
void join(size_t x, size_t y)
Definition
disjoint_set.h:41
DisjointSet::DisjointSet
DisjointSet(size_t size)
Definition
disjoint_set.h:19
DisjointSet::find
size_t find(size_t x)
Definition
disjoint_set.h:27
array
Definition
cycles/util/array.h:25
y
y
Definition
compositor_morphological_blur_info.hh:15
array.h
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
CCL_NAMESPACE_BEGIN
Definition
python.cpp:44
Generated on Sat Oct 4 2025 05:32:23 for Blender by
doxygen
1.14.0