GRSISort
Created by P.C. Bender
Developement Team: P.C. Bender, R. Dunlop, V. Bildstein
An extension of the ROOT analysis Framework
combinations.h
Go to the documentation of this file.
1 #ifndef _COMBINATIONS_H_
2 #define _COMBINATIONS_H_
3 
4 class combinations {
5 public:
6  class iterator {
7  public:
8  iterator(std::vector<double>& points, size_t n, bool at_beginning)
9  : fPoints(points), fPoints_used(fPoints.size()), fPast_end(false)
10  {
11  if(at_beginning) {
12  std::fill(fPoints_used.begin(), fPoints_used.begin() + n, true);
13  } else {
14  fPast_end = true;
15  }
16  }
17 
18  std::vector<double> operator*() const
19  {
20  std::vector<double> values;
21  for(size_t i = 0; i < fPoints_used.size(); i++) {
22  if(fPoints_used[i]) {
23  values.push_back(fPoints[i]);
24  }
25  }
26  return values;
27  }
28 
30  {
31  fPast_end = !std::prev_permutation(fPoints_used.begin(), fPoints_used.end());
32  return *this;
33  }
34 
36  {
37  iterator temp = *this;
38  ++(*this);
39  return temp;
40  }
41 
42  bool operator==(const iterator& other) const
43  {
44  if(&fPoints != &other.fPoints || fPoints_used.size() != other.fPoints_used.size()) {
45  return false;
46  }
47  if(fPast_end && other.fPast_end) {
48  return true;
49  }
50 
51  for(size_t i = 0; i < fPoints_used.size(); i++) {
52  if(fPoints_used[i] != other.fPoints_used[i]) {
53  return false;
54  }
55  }
56 
57  return true;
58  }
59 
60  bool operator!=(const iterator& other) const { return !(*this == other); }
61 
62  private:
63  std::vector<double>& fPoints;
64  std::vector<bool> fPoints_used;
65  bool fPast_end;
66  };
67 
68  combinations(std::vector<double>& points, size_t n) : fPoints(points), fN(n) {}
69 
70  iterator begin() const { return iterator(fPoints, fN, true); }
71 
72  iterator end() const { return iterator(fPoints, fN, false); }
73 
74 private:
75  std::vector<double>& fPoints;
76  size_t fN;
77 };
78 
79 #endif
combinations(std::vector< double > &points, size_t n)
Definition: combinations.h:68
std::vector< double > & fPoints
Definition: combinations.h:75
iterator & operator++()
Definition: combinations.h:29
iterator begin() const
Definition: combinations.h:70
std::vector< bool > fPoints_used
Definition: combinations.h:64
bool operator!=(const iterator &other) const
Definition: combinations.h:60
iterator(std::vector< double > &points, size_t n, bool at_beginning)
Definition: combinations.h:8
std::vector< double > operator*() const
Definition: combinations.h:18
bool operator==(const iterator &other) const
Definition: combinations.h:42
iterator operator++(int)
Definition: combinations.h:35
iterator end() const
Definition: combinations.h:72
std::vector< double > & fPoints
Definition: combinations.h:63