14#include <lagrange/internal/invert_mapping.h>
15#include <lagrange/utils/DisjointSets.h>
26template <
typename Index>
55template <
typename Index>
67 Index num_elements =
static_cast<Index
>(element_representative.size());
70 num_representatives = 0;
71 std::fill(element_representative.begin(), element_representative.end(), invalid<Index>());
72 for (Index e = 0; e < num_elements; ++e) {
73 Index r = unified_indices.
find(e);
74 if (element_representative[r] == invalid<Index>()) {
75 element_representative[r] = num_representatives++;
77 element_representative[e] = element_representative[r];
81 {element_representative.data(), element_representative.size()},
83 sorted_elements = std::move(mapping.data);
84 representative_offsets = std::move(mapping.offsets);
94template <
typename Index>
118template <
typename Index,
typename Function>
120bucket_sort(std::vector<Index>& elements, Index num_buckets, Function get_representative)
126 num_representatives = num_buckets;
127 auto mapping = invert_mapping<Index>(
128 static_cast<Index
>(elements.size()),
130 num_representatives);
131 elements = std::move(mapping.data);
132 representative_offsets = std::move(mapping.offsets);
Disjoint sets computation.
Definition: DisjointSets.h:32
size_t size() const
Get the number of entries in total.
Definition: DisjointSets.h:56
IndexType find(IndexType i)
Find the root index corresponding to index i.
Definition: DisjointSets.cpp:35
#define la_debug_assert(...)
Debug assertion check.
Definition: assert.h:189
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition: span.h:27
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
BucketSortResult< Index > bucket_sort(DisjointSets< Index > &unified_indices, span< Index > element_representative)
Performs a bucket sort over a range of elements.
Definition: bucket_sort.h:56
InverseMapping< Index > invert_mapping(Index num_source_elements, Function old_to_new, Index num_target_elements=invalid< Index >())
Compute the target-to-source (i.e.
Definition: invert_mapping.h:61
Bucket sort offset infos.
Definition: bucket_sort.h:96
Index num_representatives
Number of representatives in the input disjoint set.
Definition: bucket_sort.h:98
std::vector< Index > representative_offsets
Vector of size num_representatives + 1 storing the start/end of each disjoint set in the sorted eleme...
Definition: bucket_sort.h:102
Bucket sort result object.
Definition: bucket_sort.h:28
std::vector< Index > sorted_elements
Sorted element in the input range.
Definition: bucket_sort.h:33
Index num_representatives
Number of representatives in the input disjoint set.
Definition: bucket_sort.h:30
std::vector< Index > representative_offsets
Vector of size num_representatives + 1 storing the start/end of each disjoint set in the sorted eleme...
Definition: bucket_sort.h:37