PCB Environment 2

Loading...
Searching...
No Matches
LubySequence.hpp
1
2#ifndef GYM_PCB_MATH_LUBYSEQUENCE_H
3#define GYM_PCB_MATH_LUBYSEQUENCE_H
4
5#include <vector>
6
7// 1, 1 2, 1 1 2 4, 1 1 2 1 1 2 4 8, ...
8
9 class LubySequence
10{
11 public:
12 LubySequence() { reset(); }
13 void reset();
14 uint next();
15 private:
16 std::vector<uint> values;
17 uint it;
18};
19 inline void LubySequence::reset()
20{
21 values.resize(1);
22 values[0] = 1;
23 it = 0;
24}
25 inline uint LubySequence::next()
26{
27 if (it < values.size())
28 return values[it++];
29 values.insert(values.end(), values.begin(), values.end());
30 values.push_back(values.back() * 2);
31 it = 1;
32 return 1;
33}
34
35#endif // GYM_PCB_MATH_LUBYSEQUENCE_H