ARTS  2.3.1285(git:92a29ea9-dirty)
sorting.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2012 Oliver Lemke <olemke@core-dump.info>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA.
17  */
18 
20 // File description
22 
31 #ifndef sorting_h
32 #define sorting_h
33 
34 #include <algorithm>
35 #include <functional>
36 
37 #include "array.h"
38 #include "matpack.h"
39 
47 template <typename T>
48 class IndexComp : public binary_function<Index, Index, bool> {
49  const T& m_data;
50 
51  public:
52  explicit IndexComp(const T& data) : m_data(data) {}
53 
54  bool operator()(Index a, Index b) const { return (m_data[a] < m_data[b]); }
55 };
56 
72 template <typename T>
73 void get_sorted_indexes(ArrayOfIndex& sorted, const T& data) {
74  sorted.resize(0);
75 
76  Index i = 0;
77  for (typename T::const_iterator it = data.begin(); it != data.end(); ++it) {
78  sorted.push_back(i);
79  i++;
80  }
81 
82  sort(sorted.begin(), sorted.end(), IndexComp<T>(data));
83 }
84 
85 #endif /* sorting_h */
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
This file contains the definition of Array.
bool operator()(Index a, Index b) const
Definition: sorting.h:54
IndexComp(const T &data)
Definition: sorting.h:52
IndexComp.
Definition: sorting.h:48
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:73
This can be used to make arrays out of anything.
Definition: array.h:40
const T & m_data
Definition: sorting.h:49