25 #ifndef __MLPACK_METHODS_EMST_UNION_FIND_HPP
26 #define __MLPACK_METHODS_EMST_UNION_FIND_HPP
48 UnionFind(
const size_t size) : parent(size), rank(size)
50 for (
size_t i = 0; i < size; ++i)
66 size_t Find(
const size_t x)
75 parent[x] =
Find(parent[x]);
86 void Union(
const size_t x,
const size_t y)
88 const size_t xRoot =
Find(x);
89 const size_t yRoot =
Find(y);
95 else if (rank[xRoot] == rank[yRoot])
97 parent[yRoot] = parent[xRoot];
98 rank[xRoot] = rank[xRoot] + 1;
100 else if (rank[xRoot] > rank[yRoot])
102 parent[yRoot] = xRoot;
106 parent[xRoot] = yRoot;
114 #endif // __MLPACK_METHODS_EMST_UNION_FIND_HPP
UnionFind(const size_t size)
Construct the object with the given size.
A Union-Find data structure.
arma::Col< size_t > parent
Linear algebra utility functions, generally performed on matrices or vectors.
void Union(const size_t x, const size_t y)
Union the components containing x and y.
size_t Find(const size_t x)
Returns the component containing an element.
~UnionFind()
Destroy the object (nothing to do).