15#include <lagrange/utils/assert.h>
16#include <lagrange/utils/timing.h>
18#include <tbb/parallel_sort.h>
25template <
typename Index>
38 auto key()
const {
return std::make_pair(v1, v2); }
40 bool operator<(
const UnorientedEdge& e)
const {
return key() < e.key(); }
42 bool operator!=(
const UnorientedEdge& e)
const {
return key() != e.key(); }
66template <
typename Index,
typename Func>
73 std::vector<Index> local_buffer;
74 if (vertex_to_first_edge.empty()) {
75 local_buffer.assign(num_vertices + 1, 0);
76 vertex_to_first_edge = local_buffer;
78 std::fill(vertex_to_first_edge.begin(), vertex_to_first_edge.end(), Index(0));
80 la_runtime_assert(vertex_to_first_edge.size() ==
static_cast<size_t>(num_vertices) + 1);
82 for (Index e = 0; e < num_edges; ++e) {
83 std::array<Index, 2> v = get_edge(e);
87 vertex_to_first_edge[v[0] + 1]++;
91 vertex_to_first_edge.begin(),
92 vertex_to_first_edge.end(),
93 vertex_to_first_edge.begin());
96 std::vector<Index> edge_ids(num_edges);
97 for (Index e = 0; e < num_edges; ++e) {
98 std::array<Index, 2> v = get_edge(e);
102 edge_ids[vertex_to_first_edge[v[0]]++] = e;
106 vertex_to_first_edge.rbegin(),
107 vertex_to_first_edge.rbegin() + 1,
108 vertex_to_first_edge.rend());
109 vertex_to_first_edge.front() = 0;
111 tbb::parallel_for(Index(0), num_vertices, [&](Index v) {
113 edge_ids.begin() + vertex_to_first_edge[v],
114 edge_ids.begin() + vertex_to_first_edge[v + 1],
115 [&](Index ei, Index ej) {
116 auto vi = get_edge(ei);
117 auto vj = get_edge(ej);
118 if (vi[0] > vi[1]) std::swap(vi[0], vi[1]);
119 if (vj[0] > vj[1]) std::swap(vj[0], vj[1]);
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
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
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21
std::vector< Index > fast_edge_sort(Index num_edges, Index num_vertices, Func get_edge, span< Index > vertex_to_first_edge={})
Sort an array of edges using a parallel bucket sort.
Definition: fast_edge_sort.h:67
Definition: fast_edge_sort.h:27