24 #include <boost/foreach.hpp> 25 #include <boost/cstdint.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> {
53 argless(
const T &c) :
std::binary_function<T, T, bool>(), container(c){};
54 bool operator()(
unsigned int v1,
unsigned int v2)
const {
55 return container[v1] < container[v2];
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;
75 T1 lastV = vect[indices[0]];
76 BOOST_FOREACH (
unsigned int idx, indices) {
81 res[idx] = ++currRank;
bool operator()(const std::pair< T1, T2 > &v1, const std::pair< T1, T2 > &v2) const
Utility functionality used to rank sequences.
functor for implementing > on two std::pairs. The first entries are
bool operator()(unsigned int v1, unsigned int 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
#define PRECONDITION(expr, mess)
void rankVect(const std::vector< T1 > &vect, T2 &res)
ranks the entries in a vector