source: trunk/lib/gslapi/utility.cc @ 295

Last change on this file since 295 was 295, checked in by Peter, 17 years ago

file structure modifications. NOTE, this revision is not working, please wait for the next...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 997 bytes
Line 
1// $Id: utility.cc 295 2005-04-29 09:15:58Z peter $
2
3#include <c++_tools/gslapi/gslapi_utility.h>
4
5#include <c++_tools/gslapi/vector.h>
6#include <c++_tools/utility/random_singleton.h>
7
8#include <utility>
9
10
11namespace theplu {
12namespace gslapi {
13
14
15  std::pair<size_t,
16            size_t> minmax_index(const vector& vec,
17                                 const std::vector<size_t>& subset)
18  {
19    size_t min_index = subset[0];
20    size_t max_index = subset[0];
21    for (unsigned int i=1; i<subset.size(); i++) {
22      if (vec[subset[i]] < vec[min_index])
23        min_index = subset[i];
24      else if (vec[subset[i]] > vec[max_index])
25        max_index = subset[i];
26    }
27    return std::pair<size_t,size_t>(min_index, max_index);
28  }
29
30
31
32  void shuffle(vector& invec)
33  {
34    vector vec(invec);
35    theplu::cpptools::random_singleton* 
36      rnd=theplu::cpptools::random_singleton::get_instance();
37    for (size_t i=0; i<vec.size(); i++){
38      size_t index = rnd->get_uniform_int(vec.size()-i);
39      invec[i]=vec(index);
40      vec(index)=vec(vec.size()-i-1);
41    }
42  }
43
44}} // of namespace gslapi and namespace thep
Note: See TracBrowser for help on using the repository browser.