11 #ifndef FIRM_ADT_UNIONFIND_H
12 #define FIRM_ADT_UNIONFIND_H
35 static inline void uf_init(
int *
const data,
size_t const n_elems)
37 for (
size_t i = 0; i < n_elems; ++i) {
51 static inline int uf_union(
int *
const data,
int const set1,
int const set2)
57 int const d1 = data[set1];
58 int const d2 = data[set2];
59 assert(d1 < 0 && d2 < 0);
61 int const newcount = d1 + d2;
64 data[set2] = newcount;
68 data[set1] = newcount;
83 static inline int uf_find(
int *
const data,
int const e)
87 while (data[repr] >= 0) {
94 int const next = data[t];
static void uf_init(int *const data, size_t const n_elems)
Call this to initialize an array of count elements to be used by the union find functions.
static int uf_union(int *const data, int const set1, int const set2)
Merge 2 sets (union operation).
static int uf_find(int *const data, int const e)
Finds the representative for the set with member e.