14#include <lagrange/utils/span.h>
30template <
typename IndexType>
56 size_t size()
const {
return m_parent.size(); }
61 void clear() { m_parent.clear(); }
70 IndexType
find(IndexType i);
80 IndexType
merge(IndexType i, IndexType j)
82 const auto root_i =
find(i);
83 const auto root_j =
find(j);
84 return m_parent[root_j] = root_i;
117 std::vector<IndexType> m_parent;
120template <
typename IndexType>
142 IndexType size_of(IndexType i) {
return m_size[this->
find(i)]; }
144 IndexType merge(IndexType i, IndexType j)
146 auto root_i = this->
find(i);
147 auto root_j = this->
find(j);
149 if (root_i == root_j) {
154 if (size_of(root_i) < size_of(root_j)) {
158 this->m_parent[root_j] = root_i;
159 m_size[root_i] += m_size[root_j];
165 std::vector<IndexType> m_size;
Disjoint sets computation.
Definition: DisjointSets.h:32
size_t size() const
Get the number of entries in total.
Definition: DisjointSets.h:56
IndexType merge(IndexType i, IndexType j)
Merge the disjoint set containing entry i and the disjoint set containing entry j.
Definition: DisjointSets.h:80
DisjointSets()=default
Initialize an empty disjoint sets.
IndexType find(IndexType i)
Find the root index corresponding to index i.
Definition: DisjointSets.cpp:35
DisjointSets(size_t n)
Initialize disjoint sets that contains n entries.
Definition: DisjointSets.h:44
size_t extract_disjoint_set_indices(std::vector< IndexType > &index_map)
Assign all elements their disjoint set index.
Definition: DisjointSets.cpp:60
void clear()
Clear all entries in the disjoint sets.
Definition: DisjointSets.h:61
void init(size_t n)
Initialize disjoint sets that contains n entries.
Definition: DisjointSets.cpp:28
std::vector< std::vector< IndexType > > extract_disjoint_sets()
Extract disjoint sets.
Definition: DisjointSets.cpp:46
Definition: DisjointSets.h:122
constexpr void swap(function_ref< R(Args...)> &lhs, function_ref< R(Args...)> &rhs) noexcept
Swaps the referred callables of lhs and rhs.
Definition: function_ref.h:114
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition: span.h:27
Main namespace for Lagrange.
Definition: AABBIGL.h:30