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

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

refs #439

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: sort_index.cc 1491 2008-09-11 22:41:30Z 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>& sort_index)
43  {
44    // wont compile without namespace specification
45    utility::sort_index(static_cast<StrideIterator<const double*> >(first),
46                        static_cast<StrideIterator<const double*> >(last), 
47                        sort_index);
48  }
49 
50
51  void sort_index(std::vector<double>::iterator first, 
52                  std::vector<double>::iterator last, 
53                  std::vector<size_t>& sort_index)
54  {
55    utility::sort_index(static_cast<std::vector<double>::const_iterator>(first),
56                        static_cast<std::vector<double>::const_iterator>(last),
57                        sort_index);
58  }
59
60
61  void sort_index(std::vector<double>::const_iterator first, 
62                  std::vector<double>::const_iterator last, 
63                  std::vector<size_t>& sort_index)
64  {
65    sort_index.resize(last-first);
66    gsl_sort_index(&sort_index.front(), &*first, 1, last-first);
67  }
68
69
70}}} // of namespace utility, yat, and theplu
71
Note: See TracBrowser for help on using the repository browser.