Template Class CyclicIndex
Defined in File cyclic_index.hpp
Class Documentation
-
template<uint64_t CycleLength, typename ValueType = uint64_t>
class CyclicIndex index structure that can contain logical values 0, …, CycleLength-1 but also stores an internal cycle counter to be used in compare_exchange
Public Functions
-
CyclicIndex(const CyclicIndex&) noexcept = default
-
CyclicIndex(CyclicIndex&&) noexcept = default
-
CyclicIndex &operator=(const CyclicIndex&) noexcept = default
-
CyclicIndex &operator=(CyclicIndex&&) noexcept = default
-
CyclicIndex operator+(const ValueType value) const noexcept
-
CyclicIndex next() const noexcept
-
bool isOneCycleBehind(const CyclicIndex &other) const noexcept
-
int64_t operator-(const CyclicIndex<CycleLength, ValueType> &rhs) const noexcept
Note
The difference will be negative if lhs < rhs (lhs is this) and its absolute value fits into an int64_t, otherwise it will be positive and follow the rules of modular arithmetic of unsigned types This is intended and includes the case were rhs is “very close to 0” and and lhs is “close” to the MAX of uint64_t (MAX=2^64-1). Here close means that the real absolute difference would be larger than 2^63. This is excactly the right behaviour to deal with a (theoretically possible) overflow of lhs and can be seen as lhs being interpreted as MAX + its actual value. In this case, lhs - rhs is positive even though lhs < rhs.
Public Static Attributes
-
static constexpr ValueType MAX_INDEX = CycleLength - 1U
-
static constexpr ValueType MAX_CYCLE = MAX_VALUE / CycleLength
-
static constexpr ValueType INDEX_AT_MAX_VALUE = MAX_VALUE % CycleLength
-
static constexpr ValueType OVERFLOW_START_INDEX = (INDEX_AT_MAX_VALUE + 1U) % CycleLength
-
CyclicIndex(const CyclicIndex&) noexcept = default