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