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> {
53 bool operator()(
unsigned int v1,
unsigned int v2)
const {
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) {
73 std::sort(indices.begin(), indices.end(),
argless<std::vector<T1>>(vect));
76 unsigned int lastIdx = indices[0];
77 for (
auto idx : indices) {
78 if (vect[idx] == vect[lastIdx]) {
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
bool operator()(const std::pair< T1, T2 > &v1, const std::pair< T1, T2 > &v2) const
bool operator()(const std::pair< T1, T2 > &v1, const std::pair< T1, T2 > &v2) const