15#include <lagrange/utils/assert.h>
16#include <lagrange/utils/timing.h>
19#include <lagrange/utils/warnoff.h>
20#include <tbb/parallel_sort.h>
21#include <lagrange/utils/warnon.h>
29template <
typename Index>
42 auto key()
const {
return std::make_pair(v1, v2); }
44 bool operator<(
const UnorientedEdge& e)
const {
return key() < e.key(); }
46 bool operator!=(
const UnorientedEdge& e)
const {
return key() != e.key(); }
70template <
typename Index,
typename Func>
77 std::vector<Index> local_buffer;
78 if (vertex_to_first_edge.empty()) {
79 local_buffer.assign(num_vertices + 1, 0);
80 vertex_to_first_edge = local_buffer;
82 std::fill(vertex_to_first_edge.begin(), vertex_to_first_edge.end(), Index(0));
84 la_runtime_assert(vertex_to_first_edge.size() ==
static_cast<size_t>(num_vertices) + 1);
86 for (Index e = 0; e < num_edges; ++e) {
87 std::array<Index, 2> v = get_edge(e);
91 vertex_to_first_edge[v[0] + 1]++;
95 vertex_to_first_edge.begin(),
96 vertex_to_first_edge.end(),
97 vertex_to_first_edge.begin());
100 std::vector<Index> edge_ids(num_edges);
101 for (Index e = 0; e < num_edges; ++e) {
102 std::array<Index, 2> v = get_edge(e);
106 edge_ids[vertex_to_first_edge[v[0]]++] = e;
110 vertex_to_first_edge.rbegin(),
111 vertex_to_first_edge.rbegin() + 1,
112 vertex_to_first_edge.rend());
113 vertex_to_first_edge.front() = 0;
115 tbb::parallel_for(Index(0), num_vertices, [&](Index v) {
117 edge_ids.begin() + vertex_to_first_edge[v],
118 edge_ids.begin() + vertex_to_first_edge[v + 1],
119 [&](Index ei, Index ej) {
120 auto vi = get_edge(ei);
121 auto vj = get_edge(ej);
122 if (vi[0] > vi[1]) std::swap(vi[0], vi[1]);
123 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:71
Definition: fast_edge_sort.h:31