Changeset 1492


Ignore:
Timestamp:
Sep 12, 2008, 3:15:53 AM (15 years ago)
Author:
Peter
Message:

fixes #439

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r1491 r1492  
    3333#include <fstream>
    3434#include <iostream>
     35#include <list>
    3536#include <map>
    3637#include <string>
     
    258259    }
    259260  }
    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  
    4040  void sort_index(StrideIterator<double*> first,
    4141                  StrideIterator<double*> last,
    42                   std::vector<size_t>& sort_index)
     42                  std::vector<size_t>& result)
    4343  {
    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);
    4847  }
    4948 
     
    5150  void sort_index(std::vector<double>::iterator first,
    5251                  std::vector<double>::iterator last,
    53                   std::vector<size_t>& sort_index)
     52                  std::vector<size_t>& result)
    5453  {
    55     utility::sort_index(static_cast<std::vector<double>::const_iterator>(first),
    56                         static_cast<std::vector<double>::const_iterator>(last),
    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);
    5857  }
    5958
  • trunk/yat/utility/sort_index.h

    r1491 r1492  
    2727#include <gsl/gsl_sort.h>
    2828
     29#include <algorithm>
     30#include <iterator>
    2931#include <vector>
    3032
     
    7779
    7880
     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  }
    7993
    8094}}} // of namespace utility, yat, and theplu
Note: See TracChangeset for help on using the changeset viewer.