22 #include <boost/foreach.hpp> 23 #include <boost/cstdint.hpp> 27 template <
typename T1,
typename T2>
28 struct pairGreater :
public std::binary_function<std::pair<T1,T2>,std::pair<T1,T2>,bool> {
29 bool operator() (
const std::pair<T1,T2> &v1,
const std::pair<T1,T2> &v2)
const {
30 return v1.first > v2.first;
35 template <
typename T1,
typename T2>
36 struct pairLess :
public std::binary_function<std::pair<T1,T2>,std::pair<T1,T2>,bool> {
37 bool operator() (
const std::pair<T1,T2> &v1,
const std::pair<T1,T2> &v2)
const {
38 return v1.first < v2.first;
43 class argless :
public std::binary_function<T,T,bool> {
45 argless(
const T& c) :
std::binary_function<T,T,bool>(), container(c) {};
46 bool operator() (
unsigned int v1,
unsigned int v2)
const {
47 return container[v1]<container[v2];
58 template <
typename T1,
typename T2>
59 void rankVect(
const std::vector<T1> &vect,T2 &res){
60 PRECONDITION(res.size()>=vect.size(),
"vector size mismatch");
61 unsigned int nEntries = vect.size();
63 std::vector< unsigned int > indices(nEntries);
64 for(
unsigned int i=0;i<nEntries;++i) indices[i]=i;
68 T1 lastV = vect[indices[0]];
69 BOOST_FOREACH(
unsigned int idx,indices){
74 res[idx] = ++currRank;
Utility functionality used to rank sequences.
functor for implementing > on two std::pairs. The first entries are compared.
function for implementing < on two std::pairs. The first entries are compared.
#define PRECONDITION(expr, mess)
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