32 #ifndef PLANCK_SORT_UTILS_H 33 #define PLANCK_SORT_UTILS_H 39 template<
typename It,
typename Comp>
class IdxComp__
45 IdxComp__ (It begin_, Comp comp_): begin(begin_), comp(comp_) {}
46 bool operator() (std::size_t a, std::size_t b)
const 47 {
return comp(*(begin+a),*(begin+b)); }
53 template<
typename It,
typename T2,
typename Comp>
54 inline void buildIndex (It begin, It end, std::vector<T2> &idx, Comp comp)
59 for (T2 i=0; i<num; ++i) idx[i] = i;
60 sort (idx.begin(),idx.end(),IdxComp__<It,Comp>(begin,comp));
66 template<
typename It,
typename T2>
inline void buildIndex (It begin, It end,
70 typedef typename iterator_traits<It>::value_type T;
76 template<
typename It,
typename T2>
inline void sortByIndex (It begin, It end,
77 const std::vector<T2> &idx)
80 typedef typename iterator_traits<It>::value_type T;
83 for (T2 i=0; i<num; ++i) swap(tmp[i],*(begin+i));
84 for (T2 i=0; i<num; ++i) swap(*(begin+i),tmp[idx[i]]);
91 (It begin, It end,
const std::vector<T2> &idx)
94 typedef typename iterator_traits<It>::value_type T;
96 vector<bool> done(num,
false);
108 *(begin+cnt2)=*(begin+cnt3);
118 template<
typename It,
typename Comp>
inline void indirectSort (It begin, It end,
122 vector<std::size_t> idx;
127 template<
typename It>
inline void indirectSort (It begin, It end)
130 typedef typename iterator_traits<It>::value_type T;
131 indirectSort(begin,end,less<T>());
void sortByIndex_inplace(It begin, It end, const std::vector< T2 > &idx)
void buildIndex(It begin, It end, std::vector< T2 > &idx, Comp comp)
void sortByIndex(It begin, It end, const std::vector< T2 > &idx)