|
1
|
1 #pragma once
|
|
|
2
|
|
|
3 #include "sort.h"
|
|
|
4
|
|
|
5 // 2023 additions
|
|
|
6
|
|
|
7
|
|
|
8 namespace pfc {
|
|
|
9
|
|
|
10 typedef array_t<size_t> permutation_t;
|
|
|
11
|
|
|
12 permutation_t make_identitiy(size_t);
|
|
|
13
|
|
|
14 template<typename container_t, typename compare_t>
|
|
|
15 permutation_t sort_get_permutation(container_t const& data, compare_t compare) {
|
|
|
16 const size_t count = std::size(data);
|
|
|
17 auto ret = make_identitiy( count );
|
|
|
18 if ( count > 0 ) sort_get_permutation_t(data, compare, count, ret.get_ptr() );
|
|
|
19 return ret;
|
|
|
20 }
|
|
|
21 template<typename container_t, typename compare_t>
|
|
|
22 permutation_t sort_stable_get_permutation(container_t const& data, compare_t compare) {
|
|
|
23 const size_t count = std::size(data);
|
|
|
24 auto ret = make_identitiy( count );
|
|
|
25 if ( count > 0 ) sort_stable_get_permutation_t(data, compare, count, ret.get_ptr() );
|
|
|
26 return ret;
|
|
|
27 }
|
|
|
28
|
|
|
29 template<typename container_t>
|
|
|
30 void reorder(container_t& data, permutation_t const& order) {
|
|
|
31 PFC_ASSERT( std::size(data) == std::size(order) );
|
|
|
32 reorder_t( data, order.get_ptr(), order.get_size() );
|
|
|
33 }
|
|
|
34 } |