Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef MULTI_INDEX_HH
#define MULTI_INDEX_HH
#include <dune/common/array.hh>
/** \brief N-dimensional multi-index
*/
template <int N>
class MultiIndex
: public Dune::array<unsigned int,N>
{
// The range of each component
unsigned int limit_;
public:
/** \brief Constructor with a given range for each digit */
MultiIndex(unsigned int limit)
: limit_(limit)
{
std::fill(this->begin(), this->end(), 0);
}
/** \brief Increment the MultiIndex */
MultiIndex& operator++() {
for (int i=0; i<N; i++) {
// Augment digit
(*this)[i]++;
// If there is no carry-over we can stop here
if ((*this)[i]<limit_)
break;
(*this)[i] = 0;
}
return *this;
}
/** \brief Compute how many times you can call operator++ before getting to (0,...,0) again */
size_t cycle() const {
size_t result = 1;
for (int i=0; i<N; i++)
result *= limit_;
return result;
}
};
#endif