Sorter.hpp 1.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef SORTER_HPP
#define SORTER_HPP 1

namespace Sorter {

   template <typename T>
      T pivotselect(const vector<T> &arr, int lbound, int ubound);

   template <typename T>
      void partition(vector <T> &arr, int lbound, int ubound, T pivotval, int &pivotlt, int &pivoteq);

   template <typename T>
      T median(vector <T> &array, int lbound, int ubound, int idx = -1);


   class kvpair {
      public:
      double key;
      double value;

      kvpair(double ikey = 0, double ival = 0):
         key(ikey), value(ival) {
      }

      bool operator< (const kvpair & rhs) const {
         return (key < rhs.key);
      }
      bool operator== (const kvpair & rhs) const {
         return (key == rhs.key);
      }
      operator double() const { 
         return key; 
      };
   };

   class parsorter {
      public: 
         MPI_Comm c, nestedcomm;
         int nproc, myrank, mygrank;
         vector<kvpair> * tmparray;
         vector<int> asizes;
         int ASIZE;

         parsorter * nested;

         parsorter(int isize, MPI_Comm incomm);
         ~parsorter();
         void sortkvpairs(vector<kvpair> * inarray, vector<kvpair> * tarray = 0);
   };


#include "Sorter_impl.cc"
};

// Outside the namespace

void sortarray(TArrayn::DTArray const &keys, TArrayn::DTArray const &values, 
               blitz::Array<double,3> & sortkeys,
               blitz::Array<double,3> & sortvals,
               MPI_Comm c = MPI_COMM_WORLD);

#endif