24 #include <boost/foreach.hpp>
30 template <
typename T1,
typename T2>
32 :
public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> {
34 const std::pair<T1, T2> &v2)
const {
35 return v1.first > v2.first;
41 template <
typename T1,
typename T2>
43 :
public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> {
45 const std::pair<T1, T2> &v2)
const {
46 return v1.first < v2.first;
51 class argless :
public std::binary_function<T, T, bool> {
54 bool operator()(
unsigned int v1,
unsigned int v2)
const {
65 template <
typename T1,
typename T2>
66 void rankVect(
const std::vector<T1> &vect, T2 &res) {
67 PRECONDITION(res.size() >= vect.size(),
"vector size mismatch");
68 unsigned int nEntries = rdcast<unsigned int>(vect.size());
70 std::vector<unsigned int> indices(nEntries);
71 for (
unsigned int i = 0; i < nEntries; ++i) indices[i] = i;
72 std::sort(indices.begin(), indices.end(),
argless<std::vector<T1>>(vect));
75 T1 lastV = vect[indices[0]];
76 BOOST_FOREACH (
unsigned int idx, indices) {
81 res[idx] = ++currRank;
#define PRECONDITION(expr, mess)
bool operator()(unsigned int v1, unsigned int v2) const
Utility functionality used to rank sequences.
void rankVect(const std::vector< T1 > &vect, T2 &res)
ranks the entries in a vector
functor for implementing > on two std::pairs. The first entries are
bool operator()(const std::pair< T1, T2 > &v1, const std::pair< T1, T2 > &v2) const
function for implementing < on two std::pairs. The first entries are
bool operator()(const std::pair< T1, T2 > &v1, const std::pair< T1, T2 > &v2) const