std::vector<size_t> invert_permutation(const std::vector<size_t>& perm) { std::vector<size_t> result; invert_permutation(perm, result); return result; }
void map_perm_to_graph(uint32* permutation, uint32* graph) { // there is an edge ij for any two indices i and j for which i < j and p[i] > p[j] invert_permutation(permutation); uint32 size = permutation[0]; memset(graph, 0, GRAPH_SIZE(size)*sizeof(uint32)); for (int i=0; i < size; i++) { for (int j=i+1; j < size; j++) { // i < j && p[i] > p[j] if (i < j && permutation[i+1] > permutation[j+1]) { graph[LT(i, j)] = 1; } } } invert_permutation(permutation); }
inline void sortp(Iter first, Iter last, IterP p, Cmp cmp, Alloc alloc) { typedef typename std::iterator_traits<IterP>::value_type P; typedef typename std::iterator_traits<IterP>::difference_type D; D n = last - first; std::vector<P, Alloc> q(n); for (D i = 0; i < n; ++i) q[i] = i; std::sort(make_shadow_iter(first, q.begin()), make_shadow_iter(last, q.end()), shadow_cmp<Cmp>(cmp)); invert_permutation(q.begin(), q.end()); std::copy(q.begin(), q.end(), p); }