MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / rank_elements

Function rank_elements

source/matplot/util/common.h:317–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315
316 template <class T, class T2 = T, class FN = std::less<T>>
317 void rank_elements(T first, T last, T2 rank_input,
318 FN comp = std::less<T>()) {
319 using value_and_rank =
320 std::pair<std::remove_reference_t<decltype(*first)> const *,
321 size_t>;
322 std::vector<value_and_rank> v;
323 size_t r = 0;
324 while (first != last) {
325 v.emplace_back(&(*first), r);
326 ++first;
327 ++r;
328 }
329 std::sort(v.begin(), v.end(), [comp](const auto &a, const auto &b) {
330 return comp(*a.first, *b.first);
331 });
332 for (const auto &[ptr, ranking] : v) {
333 (void)ptr;
334 *rank_input = ranking;
335 ++rank_input;
336 }
337 }
338
339 /// Cosine of argument in degreescollapse
340 MATPLOT_EXPORTS

Callers 1

paretoMethod · 0.85

Calls 2

beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected