21#include <geos/export.h>
22#include <geos/operation/cluster/Clusters.h>
43 std::iota(clusters.begin(), clusters.end(), 0);
44 std::fill(sizes.begin(), sizes.end(), 1);
48 bool same(
size_t i,
size_t j) {
49 return i == j || (find(i) == find(j));
53 bool different(
size_t i,
size_t j) {
65 while(clusters[root] != root) {
66 root = clusters[root];
70 size_t next = clusters[i];
83 void join(
size_t i,
size_t j) {
91 if ((sizes[b] > sizes[a]) || (sizes[a] == sizes[b] && b <= a)) {
95 clusters[a] = clusters[b];
102 size_t getNumClusters()
const {
107 void sortByCluster(T begin, T end) {
108 std::sort(begin, end, [
this](
size_t a,
size_t b) {
109 return find(a) < find(b);
127 std::vector<size_t> clusters;
128 std::vector<size_t> sizes;
Definition UnionFind.h:32
Clusters getClusters(std::vector< size_t > elems)
UnionFind(size_t n)
Definition UnionFind.h:39
size_t find(size_t i)
Definition UnionFind.h:62
void join(size_t i, size_t j)
Definition UnionFind.h:83
Basic namespace for all GEOS functionalities.
Definition geos.h:39