#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