32 template<
class T,
class Comparator>
34 std::vector<size_t> permutation(_vec.size());
35 std::iota(permutation.begin(), permutation.end(), 0);
36 std::sort(permutation.begin(), permutation.end(), [&](
const size_t _i,
const size_t _j){
return _comp(_vec[_i], _vec[_j]); });
42 XERUS_REQUIRE(_vec.size() == _permutation.size(),
"Vector and permutation size must coincide.");
43 std::vector<T> sorted_vec;
44 sorted_vec.reserve(_permutation.size());
45 for(
size_t i = 0; i < _permutation.size(); ++i) {
46 sorted_vec.emplace_back(std::move(_vec[_permutation[i]]));
48 _vec = std::move(sorted_vec);
51 template <
class KeyType,
class DataType,
class Comparator>
52 void simultaneous_sort( std::vector<KeyType>& _keyVector, std::vector<DataType>& _dataVector, Comparator _comp) {
53 XERUS_REQUIRE(_keyVector.size() == _dataVector.size(),
"Vector sizes must coincide.");
void simultaneous_sort(std::vector< KeyType > &_keyVector, std::vector< DataType > &_dataVector, Comparator _comp)
Header file for CHECK and REQUIRE macros.
The main namespace of xerus.
#define XERUS_REQUIRE(condition, message)
Checks whether condition is true. logs an error otherwise via XERUS_LOG(error, message).
std::vector< size_t > create_sort_permutation(const std::vector< T > &_vec, Comparator _comp)
void apply_permutation(std::vector< T > &_vec, const std::vector< size_t > &_permutation)