Changeset 1492
- Timestamp:
- Sep 12, 2008, 3:15:53 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/utility_test.cc
r1491 r1492 33 33 #include <fstream> 34 34 #include <iostream> 35 #include <list> 35 36 #include <map> 36 37 #include <string> … … 258 259 } 259 260 } 260 } 261 262 std::list<double> list; 263 for (size_t i=0; i<a.size(); ++i) 264 list.push_back(a(i)); 265 std::vector<size_t> vec5; 266 utility::sort_index(list.begin(), list.end(), vec5); 267 if (vec.size()!=vec5.size()) { 268 suite.add(false); 269 suite.err() << "size mismatch: vec.size()=" << vec.size() 270 << " vec5.size()=" << vec5.size() << "\n"; 271 } 272 else { 273 if (!suite.equal_range(vec.begin(), vec.end(), vec5.begin())){ 274 suite.add(false); 275 } 276 } 277 278 } -
trunk/yat/utility/sort_index.cc
r1491 r1492 40 40 void sort_index(StrideIterator<double*> first, 41 41 StrideIterator<double*> last, 42 std::vector<size_t>& sort_index)42 std::vector<size_t>& result) 43 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); 44 sort_index(static_cast<StrideIterator<const double*> >(first), 45 static_cast<StrideIterator<const double*> >(last), 46 result); 48 47 } 49 48 … … 51 50 void sort_index(std::vector<double>::iterator first, 52 51 std::vector<double>::iterator last, 53 std::vector<size_t>& sort_index)52 std::vector<size_t>& result) 54 53 { 55 utility::sort_index(static_cast<std::vector<double>::const_iterator>(first),56 57 sort_index);54 sort_index(static_cast<std::vector<double>::const_iterator>(first), 55 static_cast<std::vector<double>::const_iterator>(last), 56 result); 58 57 } 59 58 -
trunk/yat/utility/sort_index.h
r1491 r1492 27 27 #include <gsl/gsl_sort.h> 28 28 29 #include <algorithm> 30 #include <iterator> 29 31 #include <vector> 30 32 … … 77 79 78 80 81 // template implementation 82 83 template<typename ForwardIterator> 84 void sort_index(ForwardIterator first, ForwardIterator last, 85 std::vector<size_t>& result) 86 { 87 std::vector<double> vec; 88 vec.reserve(std::distance(first, last)); 89 std::copy(first, last, 90 std::back_insert_iterator<std::vector<double> >(vec)); 91 sort_index(vec.begin(), vec.end(), result); 92 } 79 93 80 94 }}} // of namespace utility, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.