source: trunk/yat/utility/sort_index.h @ 1707

Last change on this file since 1707 was 1603, checked in by Peter, 13 years ago

removing include

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1#ifndef _theplu_yat_utility_sort_index_
2#define _theplu_yat_utility_sort_index_
3
4// $Id: sort_index.h 1603 2008-10-27 22:07:04Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "StrideIterator.h"
26
27#include <algorithm>
28#include <iterator>
29#include <vector>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34
35  /**
36     Create a vector \a sort_index containing the indeces of elements
37     in a range [first, last). The elements of \a sort_index give the
38     index of the range element which would have been stored in that
39     position if the range had been sorted in place. The first element
40     of \a sort_index gives the index of the least element in the
41     range, and the last element of \a sort_index gives the index of
42     the greatest element in the range. The function will not affect
43     the range, i.e., ForwardIterator can be read-only.
44
45     \since New in yat 0.5
46  */
47  template<typename ForwardIterator>
48  void sort_index(ForwardIterator first, ForwardIterator last, 
49                  std::vector<size_t>& sort_index);
50   
51   
52  /**
53     Specialization for StrideIterator<double*>
54
55     \since New in yat 0.5
56  */
57  void sort_index(StrideIterator<double*> first, 
58                  StrideIterator<double*> last, 
59                  std::vector<size_t>& sort_index);
60
61  /**
62     Specialization for StrideIterator<const double*>
63
64     \since New in yat 0.5
65  */
66  void sort_index(StrideIterator<const double*> first, 
67                  StrideIterator<const double*> last, 
68                  std::vector<size_t>& sort_index);
69
70  /**
71     Specialization for std::vector<double>::iterator
72
73     \since New in yat 0.5
74  */
75  void sort_index(std::vector<double>::iterator first, 
76                  std::vector<double>::iterator last, 
77                  std::vector<size_t>& sort_index);
78
79  /**
80     Specialization for std::vector<double>::const_iterator
81
82     \since New in yat 0.5
83  */
84  void sort_index(std::vector<double>::const_iterator first, 
85                  std::vector<double>::const_iterator last, 
86                  std::vector<size_t>& sort_index);
87
88
89  //  template implementation
90
91  template<typename ForwardIterator>
92  void sort_index(ForwardIterator first, ForwardIterator last, 
93                  std::vector<size_t>& result)
94  {
95    std::vector<double> vec;
96    vec.reserve(std::distance(first, last));
97    std::copy(first, last, 
98              std::back_insert_iterator<std::vector<double> >(vec));
99    sort_index(vec.begin(), vec.end(), result);
100  }
101
102}}} // of namespace utility, yat, and theplu
103
104#endif
Note: See TracBrowser for help on using the repository browser.