source: trunk/yat/utility/sort_index.cc @ 1679

Last change on this file since 1679 was 1492, checked in by Peter, 13 years ago

fixes #439

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: sort_index.cc 1492 2008-09-12 01:15:53Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "sort_index.h"
23
24#include <gsl/gsl_sort.h>
25
26#include <vector>
27
28namespace theplu {
29namespace yat {
30namespace utility {
31
32  void sort_index(StrideIterator<const double*> first, 
33                  StrideIterator<const double*> last, 
34                  std::vector<size_t>& sort_index)
35  {
36    sort_index.resize(last-first);
37    gsl_sort_index(&sort_index.front(), &*first, first.stride(), last-first);
38  }
39   
40  void sort_index(StrideIterator<double*> first, 
41                  StrideIterator<double*> last, 
42                  std::vector<size_t>& result)
43  {
44    sort_index(static_cast<StrideIterator<const double*> >(first),
45               static_cast<StrideIterator<const double*> >(last), 
46               result);
47  }
48 
49
50  void sort_index(std::vector<double>::iterator first, 
51                  std::vector<double>::iterator last, 
52                  std::vector<size_t>& result)
53  {
54    sort_index(static_cast<std::vector<double>::const_iterator>(first),
55               static_cast<std::vector<double>::const_iterator>(last),
56               result);
57  }
58
59
60  void sort_index(std::vector<double>::const_iterator first, 
61                  std::vector<double>::const_iterator last, 
62                  std::vector<size_t>& sort_index)
63  {
64    sort_index.resize(last-first);
65    gsl_sort_index(&sort_index.front(), &*first, 1, last-first);
66  }
67
68
69}}} // of namespace utility, yat, and theplu
70
Note: See TracBrowser for help on using the repository browser.