2 #ifndef OPENGM_SORTING_HXX
3 #define OPENGM_SORTING_HXX
11 template<
class ITERATOR,
class TYPE_TO_FIND,
class INDEXTYPE>
15 ITERATOR sequenceBegin,
16 const INDEXTYPE sequenceSize,
17 const TYPE_TO_FIND & toFind,
20 if(toFind>static_cast<TYPE_TO_FIND>(sequenceBegin[sequenceSize-1]))
22 for(INDEXTYPE p=0;p<sequenceSize;++p) {
23 if(toFind<static_cast<TYPE_TO_FIND>(sequenceBegin[p]))
25 else if(toFind==static_cast<TYPE_TO_FIND>(sequenceBegin[p])) {
33 template<
class Iterator>
35 isSorted(Iterator begin, Iterator end) {
36 typedef typename std::iterator_traits<Iterator>::value_type ValueType;
37 if(std::distance(begin, end) > 1) {
38 ValueType tmp =
static_cast<ValueType
>(*begin);
43 tmp =
static_cast<ValueType
>(*begin);
50 template<
class Iterator,
class IteratorTag>
53 inline typename std::iterator_traits<Iterator>::value_type operator()(Iterator iter,
const size_t i)
const {
59 template<
class Iterator>
60 struct IteratorAt<std::random_access_iterator_tag, Iterator>
62 inline typename std::iterator_traits<Iterator>::value_type operator()(Iterator iter,
const size_t i)
const {
67 template<
class Iterator>
68 typename std::iterator_traits<Iterator>::value_type
69 iteratorAt(Iterator iterator,
const size_t i) {
70 IteratorAt<Iterator, typename std::iterator_traits<Iterator>::iterator_category> iat;
71 return iat(iterator, i);
75 struct sortPairByFirst {
76 bool operator()(
const T & a,
const T & b)
77 {
return a.first < b.first; }
80 template<
class Iterator_A,
class Iterator_B>
82 doubleSort(Iterator_A beginA, Iterator_A endA, Iterator_B beginB) {
83 typedef typename std::iterator_traits<Iterator_A>::value_type ValueType_a;
84 typedef typename std::iterator_traits<Iterator_B>::value_type ValueType_b;
85 typedef std::pair< ValueType_a, ValueType_b> PairType;
87 Iterator_A beginA_ = beginA;
88 Iterator_B beginB_ = beginB;
90 while(beginA_ != endA) {
91 pairvector[counter].first = *beginA_;
92 pairvector[counter].second = *beginB_;
97 sortPairByFirst<PairType > sortfunctor;
98 std::sort(pairvector.
begin(), pairvector.
end(), sortfunctor);
100 while(beginA != endA) {
101 *beginA = pairvector[counter].first;
102 *beginB = pairvector[counter].second;
113 #endif // #ifndef OPENGM_SORTING_HXX
Vector that stores values on the stack if size is smaller than MAX_STACK.
T const * end() const
end iterator
T const * begin() const
begin iterator