Gray Code Iterator¶
Header: fiction/utils/math/gray_code_iterator.hpp
-
class gray_code_iterator¶
An iterator type that iterates over Gray code representations for decimal numbers.
The
gray_code_iteratorclass provides an iterator for generating Gray code representations for a range of decimal numbers. It starts from a specified number and produces Gray codes in ascending order based on bitwise XOR operations.Public Functions
-
inline explicit constexpr gray_code_iterator(const uint64_t start) noexcept¶
Constructs a Gray Code Iterator with a specified starting number.
Constructs a
gray_code_iteratorthat generates Gray codes for decimal numbers starting from the givenstartnumber.- Parameters:
start – The starting decimal number for the iterator.
-
inline constexpr const uint64_t &operator*() const noexcept¶
Dereference operator. Returns a reference to the Gray code of the current iteration.
- Returns:
Reference to the current Gray code.
-
inline constexpr gray_code_iterator &operator++() noexcept¶
Prefix increment operator. Sets the number and the corresponding Gray code.
- Returns:
Reference to
this.
-
inline constexpr bool operator==(const gray_code_iterator &other) const noexcept¶
Equality comparison operator. Compares the current iterator with another iterator.
- Parameters:
other – The iterator to compare with.
- Returns:
trueif the current iterator is equal to the other iterator,falseotherwise.
-
inline constexpr bool operator!=(const gray_code_iterator &other) const noexcept¶
Inequality comparison operator. Compares the current iterator with another iterator.
- Parameters:
other – The iterator to compare with.
- Returns:
trueif the current iterator is not equal to the other iterator,falseotherwise.
-
inline constexpr bool operator<(const gray_code_iterator &other) const noexcept¶
Less-than comparison operator. Compares the current iterator with another iterator.
- Parameters:
other – The iterator to compare with.
- Returns:
trueif the current iterator is less than the other iterator,falseotherwise.
-
inline constexpr bool operator<=(const gray_code_iterator &other) const noexcept¶
Less-than or equal-to comparison operator. Compares the current iterator with another iterator.
- Parameters:
other – The iterator to compare with.
- Returns:
trueif the current iterator is less than or equal to the other iterator,falseotherwise.
-
inline constexpr int64_t operator-(const gray_code_iterator &other) const noexcept¶
Subtraction operator to calculate the difference between two gray_code_iterators.
This operator calculates the difference between the current iterator and another gray_code_iterator provided as input. The result is returned as an int64_t representing the number of positions between the iterators.
- Parameters:
other – The gray_code_iterator to subtract from the current iterator.
- Returns:
The difference between the current iterator and the input iterator as int64_t.
-
inline constexpr gray_code_iterator operator++(int) noexcept¶
Postfix increment operator. Sets the next Gray Code.
- Returns:
Copy of
thisbefore incrementing.
-
inline constexpr gray_code_iterator operator+(const int m) const noexcept¶
Addition operator. Computes the Gray code of the current iterator plus the given integer.
- Parameters:
m – The amount of Gray codes to skip.
- Returns:
Iterator of the current iterator plus the given integer.
-
inline constexpr gray_code_iterator &operator+=(const int m) noexcept¶
Addition assignment operator. Iterator is increased by given number.
- Parameters:
m – The amount of Gray codes to skip.
- Returns:
Reference to
this.
-
inline constexpr gray_code_iterator operator-(const int m) const noexcept¶
Subtraction operator. Computes the Gray code of the current iterator minus the given integer.
- Parameters:
m – The amount of Gray codes to skip.
- Returns:
Iterator of the current iterator minus the given integer.
-
inline constexpr gray_code_iterator &operator--() noexcept¶
Prefix decrement operator. Sets the previous Gray code.
- Returns:
Reference to
this.
-
inline constexpr gray_code_iterator operator--(int) noexcept¶
Postfix decrement operator. Sets the previous Gray Code.
- Returns:
Copy of
thisbefore decrementing.
-
inline constexpr gray_code_iterator &operator-=(const int m) noexcept¶
Subtraction assignment operator. Sets a previous Gray code.
- Parameters:
m – The amount of Gray codes to skip.
- Returns:
Reference to
this.
-
inline constexpr gray_code_iterator &operator=(const uint64_t m) noexcept¶
Assignment operator. Sets the current number to the given integer.
- Parameters:
m – The number to set.
-
inline constexpr uint64_t operator[](std::size_t index) const noexcept¶
Subscript operator. Returns the Gray code at a specific position in the iteration range.
- Parameters:
index – The position in the iteration range.
- Returns:
The Gray code at the specified position.
-
inline constexpr bool operator==(const uint64_t m) const noexcept¶
Equality operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is equal tom,falseotherwise.
-
inline constexpr bool operator!=(const uint64_t m) const noexcept¶
Inequality operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is not equal tom,falseotherwise.
-
inline constexpr bool operator<(const uint64_t m) const noexcept¶
Less-than operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is less thanm,falseotherwise.
-
inline constexpr bool operator<=(const uint64_t m) const noexcept¶
Less-or-equal-than operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is less than or equal tom,falseotherwise.
-
inline constexpr bool operator>(const uint64_t m) const noexcept¶
Greater-than operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is greater thanm,falseotherwise.
-
inline constexpr bool operator>=(const uint64_t m) const noexcept¶
Greater-or-equal-than operator. Compares the current number with the given integer.
- Parameters:
m – Integer to compare with.
- Returns:
trueif the current number is greater than or equal tom,falseotherwise.
-
inline explicit constexpr gray_code_iterator(const uint64_t start) noexcept¶