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
| #ifndef FIB_COLLJGBP
| #define FIB_COLLJGBP
|
| // fibonacci sequence.
| // 0,1,1,2,3,5,8,13,21,34,...
| class FibSeq
| {
| public:
| typedef uint64_t int_type;
| FibSeq(int_type limit) :
| m_limit(limit), m_cur(0), m_next(1) {}
|
| void Reset()
| {
| m_cur = 0;
| m_next = 1;
| }
| void ResetLimit(const int_type v)
| {
| m_limit = v;
| Reset();
| }
|
| int_type Limit() const { return m_limit; }
| int_type Cur() const { return m_cur; }
| int_type Inc()
| {
| if (m_next < m_limit) {
| m_next = m_next + m_cur;
| m_cur = m_next - m_cur;
| } else {
| m_cur = m_limit;
| }
| return Cur();
| }
|
| private:
| int_type m_limit;
| int_type m_cur;
| int_type m_next;
| };
|
| #endif // end of include guard: FIB_COLLJGBP
|
|