data_structures
src
data_structures
union_find
union_find_find.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* union_find_find.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2020/07/21 21:58:28 by unite #+# #+# */
10
/* Updated: 2020/09/07 22:13:31 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
union_find.h
"
15
16
size_t
union_find_find
(
const
t_union_find
*uf,
size_t
p)
17
{
18
if
(p >= uf->
size
)
19
ds_exit_set
(EINVAL);
20
while
(p != uf->
parent
[p])
21
{
22
uf->
parent
[p] = uf->
parent
[uf->
parent
[p]];
23
p = uf->
parent
[p];
24
}
25
return
(p);
26
}
s_union_find::parent
size_t * parent
An array with each element's parent.
Definition:
union_find.h:38
union_find.h
s_union_find
Weighted quick-union by rank with path compression by halving.
Definition:
union_find.h:36
union_find_find
size_t union_find_find(const t_union_find *uf, size_t p)
Returns the canonical element of the set containing the specified element.
Definition:
union_find_find.c:16
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition:
ds_exit_set.c:22
s_union_find::size
size_t size
The number of elements.
Definition:
union_find.h:40
Generated by
1.8.16