ARTS  2.2.66
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 
19 
20 
22 // File description
24 
33 #ifndef sorting_h
34 #define sorting_h
35 
36 #include <algorithm>
37 #include <functional>
38 
39 #include "matpack.h"
40 #include "array.h"
41 
49 template <typename T>
50 class IndexComp : public binary_function<Index, Index, bool>
51 {
52  const T &m_data;
53 
54 public:
55  IndexComp (const T& data ) : m_data (data) {}
56 
57  bool operator()(Index a, Index b) const
58  {
59  return (m_data[a] < m_data[b]);
60  }
61 };
62 
78 template <typename T> void
79 get_sorted_indexes (ArrayOfIndex& sorted, const T& data)
80 {
81  sorted.resize (0);
82 
83  Index i = 0;
84  for (typename T::const_iterator it = data.begin (); it != data.end (); ++it)
85  {
86  sorted.push_back (i);
87  i++;
88  }
89 
90  sort (sorted.begin(), sorted.end(), IndexComp<T>(data));
91 }
92 
93 #endif /* sorting_h */
94 
matpack.h
array.h
This file contains the definition of Array.
IndexComp::m_data
const T & m_data
Definition: sorting.h:52
Array< Index >
get_sorted_indexes
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:79
IndexComp::operator()
bool operator()(Index a, Index b) const
Definition: sorting.h:57
IndexComp::IndexComp
IndexComp(const T &data)
Definition: sorting.h:55
IndexComp
IndexComp.
Definition: sorting.h:51
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35