CluE  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
flippinggraycodebits.cpp
Go to the documentation of this file.
1 #include "../misc/flippinggraycodebits.h"
2 
3 namespace CluE
4 {
5 
7 {
8  currentPosition.push_back(1);
9  startElement.push_back(0);
10  currentElement = 0;
11  gcs=0;
12 }
13 
15 {
16  if(this->gcs != 0)
17  delete this->gcs;
18 }
19 
20 
22 {
23  size_t result = next(0);
24  currentElement = result;
25 
26  return result;
27 }
28 
29 size_t GraycodeSequence::next(size_t index)
30 {
31  size_t result;
32  switch(currentPosition[index])
33  {
34  case 0:
35  case 2:
36  result = startElement[index];
37  break;
38  case 1:
39  result = startElement[index]+1;
40  break;
41  case 3:
42  if(startElement.size()-1 == index)
43  {
44  size_t start = startElement[index] + 2;
45  startElement.push_back(start);
46  currentPosition.push_back(0);
47  }
48  result = next(index+1);
49  break;
50  }
51  currentPosition[index] = (currentPosition[index]+1) % 4;
52 
53  return result;
54 }
55 
57 {
58  return currentElement;
59 }
60 
61 }
std::vector< int > currentPosition
std::vector< size_t > startElement
size_t current() const
Returns the index of the current flipping bit.
size_t next()
Returns the index of the next flipping bit.