5 #ifndef TCPSPSUITE_SORTING_HPP
6 #define TCPSPSUITE_SORTING_HPP
10 class DefaultIndexGetter {
12 static unsigned int get(
unsigned int i) {
return i ; }
15 template<
class T,
class IC,
class IndexGetter = DefaultIndexGetter>
16 void apply_permutation(std::vector<T> & container,
const IC & indices)
19 std::vector<bool> done(container.size(),
false);
22 for (
unsigned int i = 0 ; i < container.size() ; ++i) {
28 unsigned int index = IndexGetter::get(indices[i]);
29 container[i] = container[index];
31 while (IndexGetter::get(indices[index]) != i) {
32 container[index] = container[IndexGetter::get(indices[index])];
34 index = IndexGetter::get(indices[index]);
37 container[index] = cpy;
44 #endif //TCPSPSUITE_SORTING_HPP