ARTS 2.5.0 (git: 9ee3ac6c)
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
47template <typename T>
48class 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
72template <typename T>
73void 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 */
This file contains the definition of Array.
void * data
IndexComp.
Definition: sorting.h:48
const T & m_data
Definition: sorting.h:49
bool operator()(Index a, Index b) const
Definition: sorting.h:54
IndexComp(const T &data)
Definition: sorting.h:52
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define a
#define b
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:73