yat
0.8.3pre
|
00001 #ifndef _theplu_yat_utility_sort_index_ 00002 #define _theplu_yat_utility_sort_index_ 00003 00004 // $Id: sort_index.h 2202 2010-02-21 18:39:13Z peter $ 00005 00006 /* 00007 Copyright (C) 2008, 2010 Peter Johansson 00008 00009 This file is part of the yat library, http://dev.thep.lu.se/yat 00010 00011 The yat library is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 3 of the 00014 License, or (at your option) any later version. 00015 00016 The yat library is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with yat. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #include "StrideIterator.h" 00026 00027 #include <boost/concept_check.hpp> 00028 00029 #include <algorithm> 00030 #include <iterator> 00031 #include <vector> 00032 00033 namespace theplu { 00034 namespace yat { 00035 namespace utility { 00036 00049 template<typename ForwardIterator> 00050 void sort_index(ForwardIterator first, ForwardIterator last, 00051 std::vector<size_t>& sort_index); 00052 00053 00059 void sort_index(StrideIterator<double*> first, 00060 StrideIterator<double*> last, 00061 std::vector<size_t>& sort_index); 00062 00068 void sort_index(StrideIterator<const double*> first, 00069 StrideIterator<const double*> last, 00070 std::vector<size_t>& sort_index); 00071 00077 void sort_index(std::vector<double>::iterator first, 00078 std::vector<double>::iterator last, 00079 std::vector<size_t>& sort_index); 00080 00086 void sort_index(std::vector<double>::const_iterator first, 00087 std::vector<double>::const_iterator last, 00088 std::vector<size_t>& sort_index); 00089 00090 00091 // template implementation 00092 00093 template<typename ForwardIterator> 00094 void sort_index(ForwardIterator first, ForwardIterator last, 00095 std::vector<size_t>& result) 00096 { 00097 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>)); 00098 std::vector<double> vec; 00099 vec.reserve(std::distance(first, last)); 00100 std::copy(first, last, 00101 std::back_insert_iterator<std::vector<double> >(vec)); 00102 sort_index(vec.begin(), vec.end(), result); 00103 } 00104 00105 }}} // of namespace utility, yat, and theplu 00106 00107 #endif