113 if ( initial_offset < 0 || initial_offset >
offset_max ) {
114 std::string error(
"n_aryGrayCodeCounter::initialize: Wrong value of initial_offset");
121 for (
size_t idx = 0; idx < static_cast<size_t>(
n_ary_limits.
size()); idx++) {
122 counter_chain[
static_cast<int>(idx)] = static_cast<int>(initial_offset % static_cast<int64_t>(
n_ary_limits[static_cast<int>(idx)]));
123 initial_offset /=
static_cast<int64_t
>(
n_ary_limits[
static_cast<int>(idx)]);
129 for (
unsigned long long jdx = static_cast<unsigned long long>(
n_ary_limits.
size()-1); jdx != ~0ULL; jdx--) {
130 size_t jdx_size =
static_cast<size_t>(jdx);
131 int jdx_int =
static_cast<int>(jdx);
133 parity = parity ^ (
gray_code[jdx_size] & 1);
163 int&& ret =
next(changed_index);
177 int value_prev, value;
178 int&& ret =
next( changed_index, value_prev, value);
201 bool update_counter =
true;
202 int counter_chain_idx = 0;
203 while( update_counter ) {
207 update_counter =
false;
211 update_counter =
true;
221 for (
size_t jdx = static_cast<size_t>(
n_ary_limits.
size()-1); jdx != ~0ULL; jdx--) {
222 int jdx_int =
static_cast<int>(jdx);
224 parity = parity ^ (gray_code_new_val & 1);
226 if ( gray_code_new_val !=
gray_code[jdx] ) {
228 value = gray_code_new_val;
230 changed_index =
static_cast<int>(jdx);
256 if (L == 0)
return 0;
257 if (counter_pos < 0) counter_pos = 0;
258 if (counter_pos >= L) counter_pos = L - 1;
279 int64_t new_offset = 0;
281 for (
int j = 0; j <
L; ++j) {
288 if (new_offset <= offset || new_offset >
offset_max)
return 0;
294 return new_offset -
offset;
GrayCode gray_code
the current gray code associated to the offset value
int64_t offset_max
the maximal offset in the counter offset = prod( n_ary_limits[i] )
n_aryGrayCodeCounter()
Default constructor of the class.
int64_t offset
the current offset in the counter 0<= offset <= offset_max
matrix_base< scalar > copy() const
Call to create a copy of the matrix.
int64_t advance(int counter_pos)
Advance the n-ary Gray code counter by incrementing the digit at a specified position.
scalar * data
pointer to the stored data
void set_offset_max(const int64_t &value)
int next()
Iterate the counter to the next value.
void initialize()
Initialize the gray counter by zero offset.
GrayCode_base< int > GrayCode
alias for Piquassoboost state with values of type int64_t
int size() const
Call to get the number of the allocated elements.
GrayCode_base copy() const
Call to create a copy of the state.
GrayCode get()
Get the current gray code counter value.
matrix_base< int > n_ary_limits
The maximal value of the individual gray code elements.
matrix_base< int > counter_chain
The incremental counter chain associated to the gray code.