25 static_assert(NUMBITS > 0);
31 constexpr BitField(std::initializer_list<unsigned int> list);
43 constexpr bool IsSet(
const uint64_t bitIndex)
const;
45 template <u
int64_t bitIndex>
constexpr bool IsSet()
const;
51 constexpr void SetBit(
const uint64_t bitIndex);
53 constexpr void SetBitIf(
const uint64_t bitIndex, uint64_t cond);
55 template <u
int64_t bitIndex>
constexpr void SetBit();
72 static constexpr uint64_t
BASE = NUMBITS > 32 ? 64 : NUMBITS > 16 ? 32 : NUMBITS > 8 ? 16 : 8;
101 return this->bits[index];
107 this->bits[index] = value;
117 for (i = 0; i <
size; i++)
133 for (
auto bit : list)
142template<
unsigned int NUMBITS>
145 for (
IndexT i = 0; i < NUMBITS; i++)
147 if (mask & (1ull << i))
157template <
unsigned int NUMBITS>
174template <
unsigned int NUMBITS>
178 return !(*
this == rhs);
184template <
unsigned int NUMBITS>
189 const TYPE i = (1ull << (bitIndex %
BASE));
191 return (this->
bits[index] & i) == i;
197template <
unsigned int NUMBITS>
198template <u
int64_t bitIndex>
202 static_assert(bitIndex < NUMBITS);
203 constexpr TYPE i = (1ull << (bitIndex %
BASE));
204 constexpr TYPE index = bitIndex /
BASE;
205 return (this->
bits[index] & i) == i;
211template <
unsigned int NUMBITS>
216 for (i = 0; i <
size; i++)
225template <
unsigned int NUMBITS>
230 for (i = 0; i <
size; i++)
232 if (this->
bits[i] != 0)
243template <
unsigned int NUMBITS>
249 const TYPE bit = (1ull << (i %
BASE));
250 this->
bits[index] |= bit;
256template <
unsigned int NUMBITS>
262 const TYPE bit = (1ull << (i %
BASE));
263 this->
bits[index] |= bit * cond;
269template <
unsigned int NUMBITS>
274 static_assert(i < NUMBITS);
276 constexpr TYPE bit = (1ull << (i %
BASE));
277 this->
bits[index] |= bit;
283template <
unsigned int NUMBITS>
289 const TYPE bit = ~(1ull << (i %
BASE));
290 this->
bits[index] &= bit;
296template <
unsigned int NUMBITS>
301 return this->
bits[section] == 0;
307template <
unsigned int NUMBITS>
322template <
unsigned int NUMBITS>
Implements large bit field.
Definition bitfield.h:24
constexpr bool operator==(const BitField< NUMBITS > &rhs) const
equality operator
Definition bitfield.h:159
static constexpr uint64_t BASE
Definition bitfield.h:72
void ClearBit(const uint64_t bitIndex)
clear a bit by index
Definition bitfield.h:285
constexpr bool operator!=(const BitField< NUMBITS > &rhs) const
inequality operator
Definition bitfield.h:176
BitType< BASE >::T GetBits(size_t index) const
Definition bitfield.h:98
BitField(const BitField< NUMBITS > &rhs)=default
copy constructor
bool IsNull() const
return true if all bits are 0
Definition bitfield.h:227
constexpr void SetBit()
set a bit by index
Definition bitfield.h:272
BitField(const uint64_t mask)
Construct from mask.
Definition bitfield.h:143
bool SectionIsNull(uint64_t section) const
Check if a section of the bitfield is set.
Definition bitfield.h:298
void SetBits(size_t index, BitType< BASE >::T value)
Definition bitfield.h:104
static constexpr BitField< NUMBITS > And(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to AND combination
Definition bitfield.h:324
typename BitType< BASE >::T TYPE
Definition bitfield.h:93
constexpr void SetBitIf(const uint64_t bitIndex, uint64_t cond)
set a bit by index. Multiplies the bit with cond before OR-ing which means it won't set the bit if mu...
Definition bitfield.h:258
constexpr void SetBit(const uint64_t bitIndex)
set a bit by index
Definition bitfield.h:245
constexpr BitField(std::initializer_list< unsigned int > list)
constructs a bitfield based on multiple values
Definition bitfield.h:126
void Clear()
clear content
Definition bitfield.h:213
BitField()
constructor
Definition bitfield.h:114
constexpr bool IsSet(const uint64_t bitIndex) const
Check if single bit is set.
Definition bitfield.h:186
TYPE bits[size]
Definition bitfield.h:95
constexpr bool IsSet() const
Check if single bit is set.
Definition bitfield.h:200
static constexpr BitField< NUMBITS > Or(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to OR combination
Definition bitfield.h:309
static const int size
Definition bitfield.h:73
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
constexpr uint64_t SetBit(uint64_t mask, uint8_t bit)
Definition bit.h:21
uint16_t T
Definition bitfield.h:82
uint32_t T
Definition bitfield.h:86
uint64_t T
Definition bitfield.h:90
uint8_t T
Definition bitfield.h:78
int IndexT
Definition types.h:41