15 #ifndef MLPACK_METHODS_EMST_UNION_FIND_HPP
16 #define MLPACK_METHODS_EMST_UNION_FIND_HPP
33 arma::Col<size_t> parent;
38 UnionFind(
const size_t size) : parent(size), rank(size)
40 for (
size_t i = 0; i < size; ++i)
56 size_t Find(
const size_t x)
65 parent[x] =
Find(parent[x]);
76 void Union(
const size_t x,
const size_t y)
78 const size_t xRoot =
Find(x);
79 const size_t yRoot =
Find(y);
85 else if (rank[xRoot] == rank[yRoot])
87 parent[yRoot] = parent[xRoot];
88 rank[xRoot] = rank[xRoot] + 1;
90 else if (rank[xRoot] > rank[yRoot])
92 parent[yRoot] = xRoot;
96 parent[xRoot] = yRoot;
104 #endif // MLPACK_METHODS_EMST_UNION_FIND_HPP