PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
ArgSort.h
Go to the documentation of this file.
1
9
10#ifndef PBAT_COMMON_ARG_SORT_H
11#define PBAT_COMMON_ARG_SORT_H
12
13#include "pbat/Aliases.h"
14
15#include <algorithm>
16#include <concepts>
17#include <numeric>
18
19namespace pbat {
20namespace common {
21
31template <std::integral TIndex, class FLess>
32auto ArgSort(TIndex n, FLess less) -> Eigen::Vector<TIndex, Eigen::Dynamic>
33{
34 using IndexVectorType = Eigen::Vector<TIndex, Eigen::Dynamic>;
35 IndexVectorType inds(n);
36 std::iota(inds.begin(), inds.end(), TIndex(0));
37 std::stable_sort(inds.begin(), inds.end(), less);
38 return inds;
39}
40
41} // namespace common
42} // namespace pbat
43
44#endif // PBAT_COMMON_ARG_SORT_H
Common functionality.
Definition ArgSort.h:20
auto ArgSort(TIndex n, FLess less) -> Eigen::Vector< TIndex, Eigen::Dynamic >
Computes the indices that would sort an array.
Definition ArgSort.h:32
The main namespace of the library.
Definition Aliases.h:15