Mercurial > foo_out_sdl
diff foosdk/sdk/pfc/sort2.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/foosdk/sdk/pfc/sort2.h Mon Jan 05 02:15:46 2026 -0500 @@ -0,0 +1,34 @@ +#pragma once + +#include "sort.h" + +// 2023 additions + + +namespace pfc { + + typedef array_t<size_t> permutation_t; + + permutation_t make_identitiy(size_t); + + template<typename container_t, typename compare_t> + permutation_t sort_get_permutation(container_t const& data, compare_t compare) { + const size_t count = std::size(data); + auto ret = make_identitiy( count ); + if ( count > 0 ) sort_get_permutation_t(data, compare, count, ret.get_ptr() ); + return ret; + } + template<typename container_t, typename compare_t> + permutation_t sort_stable_get_permutation(container_t const& data, compare_t compare) { + const size_t count = std::size(data); + auto ret = make_identitiy( count ); + if ( count > 0 ) sort_stable_get_permutation_t(data, compare, count, ret.get_ptr() ); + return ret; + } + + template<typename container_t> + void reorder(container_t& data, permutation_t const& order) { + PFC_ASSERT( std::size(data) == std::size(order) ); + reorder_t( data, order.get_ptr(), order.get_size() ); + } +} \ No newline at end of file
