23 #include <boost/foreach.hpp> 24 #include <boost/cstdint.hpp> 29 template <
typename T1,
typename T2>
31 :
public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> {
33 const std::pair<T1, T2> &v2)
const {
34 return v1.first > v2.first;
40 template <
typename T1,
typename T2>
42 :
public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool> {
44 const std::pair<T1, T2> &v2)
const {
45 return v1.first < v2.first;
50 class argless :
public std::binary_function<T, T, bool> {
52 argless(
const T &c) :
std::binary_function<T, T, bool>(), container(c){};
53 bool operator()(
unsigned int v1,
unsigned int v2)
const {
54 return container[v1] < container[v2];
64 template <
typename T1,
typename T2>
65 void rankVect(
const std::vector<T1> &vect, T2 &res) {
66 PRECONDITION(res.size() >= vect.size(),
"vector size mismatch");
67 unsigned int nEntries = rdcast<unsigned int>(vect.size());
69 std::vector<unsigned int> indices(nEntries);
70 for (
unsigned int i = 0; i < nEntries; ++i) indices[i] = i;
74 T1 lastV = vect[indices[0]];
75 BOOST_FOREACH (
unsigned int idx, indices) {
80 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