00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00024
00033 #ifndef sorting_h
00034 #define sorting_h
00035
00036 #include <algorithm>
00037 #include <functional>
00038
00039 #include "matpack.h"
00040 #include "array.h"
00041
00049 template <typename T>
00050 class IndexComp : public binary_function<Index, Index, bool>
00051 {
00052 const T &m_data;
00053
00054 public:
00055 IndexComp (const T& data ) : m_data (data) {}
00056
00057 bool operator()(Index a, Index b) const
00058 {
00059 return (m_data[a] < m_data[b]);
00060 }
00061 };
00062
00078 template <typename T> void
00079 get_sorted_indexes (ArrayOfIndex& sorted, const T& data)
00080 {
00081 sorted.resize (0);
00082
00083 Index i = 0;
00084 for (typename T::const_iterator it = data.begin (); it != data.end (); ++it)
00085 {
00086 sorted.push_back (i);
00087 i++;
00088 }
00089
00090 sort (sorted.begin(), sorted.end(), IndexComp<T>(data));
00091 }
00092
00093 #endif
00094