diff --git a/framework/std_utils/src/mm/permutation.hpp b/framework/std_utils/src/mm/permutation.hpp new file mode 100644 index 0000000..c4a1f29 --- /dev/null +++ b/framework/std_utils/src/mm/permutation.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include + +namespace MM::std_utils { + +// TODO: move to some lib in engine +// TODO: determain the ideal sort +// uses std::sort rn +template +std::vector generate_sort_permutation(size_t size, F&& sort_fn) { + std::vector index_mapping; + + index_mapping.resize(size); + std::iota(index_mapping.begin(), index_mapping.end(), 0); + + std::sort(index_mapping.begin(), index_mapping.end(), sort_fn); + + return index_mapping; +} + +// TODO: reimplement, this naive solution is kind of costly +template +void apply_permutation(ContainerType& vec, const std::vector& perm) { + ContainerType new_vec(vec.size()); + + for (size_t i = 0; i < vec.size(); i++) { + new_vec[i] = vec[perm[i]]; // thx ec and random guy + } + + vec = std::move(new_vec); +} + +} // MM::std_utils +