Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Algorithms.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 *
4 * Copyright (c) 2022, CERN
5 *
6 * Redistribution and use in source and binary forms,
7 * with or without modification, are permitted according to the terms
8 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
9 */
10
11#ifndef RooFit_Detail_Algorithms_h
12#define RooFit_Detail_Algorithms_h
13
14#include <vector>
15
16namespace RooFit {
17namespace Detail {
18
19//_____________________________________________________________________________
20// from http://stackoverflow.com/a/5279601
21template <typename T>
22void cartesianProduct(std::vector<std::vector<T>> &out, std::vector<std::vector<T>> &in)
23{
24 struct Digits {
25 typename std::vector<T>::const_iterator begin;
26 typename std::vector<T>::const_iterator end;
27 typename std::vector<T>::const_iterator me;
28 };
29
30 std::vector<Digits> vd;
31 vd.reserve(in.size());
32
33 for (auto it = in.begin(); it != in.end(); ++it) {
34 Digits d = {(*it).begin(), (*it).end(), (*it).begin()};
35 vd.push_back(d);
36 }
37
38 while (true) {
39 std::vector<T> result;
40 for (auto it = vd.begin(); it != vd.end(); ++it) {
41 result.push_back(*(it->me));
42 }
43 out.push_back(result);
44
45 for (auto it = vd.begin();;) {
46 ++(it->me);
47 if (it->me == it->end) {
48 if (it + 1 == vd.end()) {
49 return;
50 } else {
51 it->me = it->begin;
52 ++it;
53 }
54 } else {
55 break;
56 }
57 }
58 }
59}
60
61//_____________________________________________________________________________
62// from http://stackoverflow.com/a/5097100/8747
63template <typename Iterator>
64bool nextCombination(const Iterator first, Iterator k, const Iterator last)
65{
66 if ((first == last) || (first == k) || (last == k)) {
67 return false;
68 }
69 Iterator itr1 = first;
70 Iterator itr2 = last;
71 ++itr1;
72 if (last == itr1) {
73 return false;
74 }
75 itr1 = last;
76 --itr1;
77 itr1 = k;
78 --itr2;
79 while (first != itr1) {
80 if (*--itr1 < *itr2) {
81 Iterator j = k;
82 while (!(*itr1 < *j))
83 ++j;
84 iter_swap(itr1, j);
85 ++itr1;
86 ++j;
87 itr2 = k;
88 rotate(itr1, j, last);
89 while (last != j) {
90 ++j;
91 ++itr2;
92 }
93 rotate(k, itr2, last);
94 return true;
95 }
96 }
97 rotate(first, k, last);
98 return false;
99}
100
101} // namespace Detail
102} // namespace RooFit
103
104#endif
#define d(i)
Definition RSha256.hxx:102
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
void cartesianProduct(std::vector< std::vector< T > > &out, std::vector< std::vector< T > > &in)
Definition Algorithms.h:22
bool nextCombination(const Iterator first, Iterator k, const Iterator last)
Definition Algorithms.h:64
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26