source: trunk/c++_tools/gslapi/utility.cc @ 610

Last change on this file since 610 was 377, checked in by Jari Häkkinen, 16 years ago

Replaced utility::random_singleton.* with random::random.*

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 895 bytes
Line 
1// $Id: utility.cc 377 2005-08-07 23:33:13Z jari $
2
3#include <c++_tools/gslapi/utility.h>
4
5#include <c++_tools/gslapi/vector.h>
6#include <c++_tools/random/random.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    random::DiscreteUniform rnd;
36    for (size_t i=0; i<vec.size(); i++){
37      size_t index = rnd(vec.size()-i);
38      invec[i]=vec(index);
39      vec(index)=vec(vec.size()-i-1);
40    }
41  }
42
43}} // of namespace gslapi and namespace thep
Note: See TracBrowser for help on using the repository browser.