25 static_assert(NUMBITS > 0);
31 constexpr BitField(std::initializer_list<unsigned int> list);
41 constexpr bool IsSet(
const uint64_t bitIndex)
const;
43 template <u
int64_t bitIndex>
constexpr bool IsSet()
const;
49 constexpr void SetBit(
const uint64_t bitIndex);
51 constexpr void SetBitIf(
const uint64_t bitIndex, uint64_t cond);
53 template <u
int64_t bitIndex>
constexpr void SetBit();
70 static constexpr uint64_t
BASE = NUMBITS > 32 ? 64 : NUMBITS > 16 ? 32 : NUMBITS > 8 ? 16 : 8;
102 for (i = 0; i < size; i++)
113 for (
IndexT i = 0; i < size; i++)
118 for (
auto bit : list)
127template <
unsigned int NUMBITS>
131 for (
IndexT i = 0; i < size; i++)
133 if (this->bits[i] != rhs.
bits[i])
144template <
unsigned int NUMBITS>
148 return !(*
this == rhs);
154template <
unsigned int NUMBITS>
159 const TYPE i = (1ull << (bitIndex % BASE));
160 const TYPE index = bitIndex / BASE;
161 return (this->bits[index] & i) == i;
167template <
unsigned int NUMBITS>
168template <u
int64_t bitIndex>
172 static_assert(bitIndex < NUMBITS);
173 constexpr TYPE i = (1ull << (bitIndex % BASE));
174 constexpr TYPE index = bitIndex / BASE;
175 return (this->bits[index] & i) == i;
181template <
unsigned int NUMBITS>
186 for (i = 0; i < size; i++)
195template <
unsigned int NUMBITS>
200 for (i = 0; i < size; i++)
202 if (this->bits[i] != 0)
213template <
unsigned int NUMBITS>
218 const TYPE index = i / BASE;
219 const TYPE bit = (1ull << (i % BASE));
220 this->bits[index] |= bit;
226template <
unsigned int NUMBITS>
231 const TYPE index = i / BASE;
232 const TYPE bit = (1ull << (i % BASE));
233 this->bits[index] |= bit * cond;
239template <
unsigned int NUMBITS>
244 static_assert(i < NUMBITS);
245 constexpr TYPE index = i / BASE;
246 constexpr TYPE bit = (1ull << (i % BASE));
247 this->bits[index] |= bit;
253template <
unsigned int NUMBITS>
258 const TYPE index = i / BASE;
259 const TYPE bit = ~(1ull << (i % BASE));
260 this->bits[index] &= bit;
266template <
unsigned int NUMBITS>
271 return this->bits[section] == 0;
277template <
unsigned int NUMBITS>
282 for (
IndexT i = 0; i < size; i++)
292template <
unsigned int NUMBITS>
297 for (
IndexT i = 0; i < size; i++)
Implements large bit field.
Definition bitfield.h:24
constexpr bool operator==(const BitField< NUMBITS > &rhs) const
equality operator
Definition bitfield.h:129
static constexpr uint64_t BASE
Definition bitfield.h:70
void ClearBit(const uint64_t bitIndex)
clear a bit by index
Definition bitfield.h:255
constexpr bool operator!=(const BitField< NUMBITS > &rhs) const
inequality operator
Definition bitfield.h:146
BitField(const BitField< NUMBITS > &rhs)=default
copy constructor
bool IsNull() const
return true if all bits are 0
Definition bitfield.h:197
constexpr void SetBit()
set a bit by index
Definition bitfield.h:242
bool SectionIsNull(uint64_t section) const
Check if a section of the bitfield is set.
Definition bitfield.h:268
static constexpr BitField< NUMBITS > And(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to AND combination
Definition bitfield.h:294
typename BitType< BASE >::T TYPE
Definition bitfield.h:91
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:228
constexpr void SetBit(const uint64_t bitIndex)
set a bit by index
Definition bitfield.h:215
constexpr BitField(std::initializer_list< unsigned int > list)
constructs a bitfield based on multiple values
Definition bitfield.h:111
void Clear()
clear content
Definition bitfield.h:183
BitField()
constructor
Definition bitfield.h:99
constexpr bool IsSet(const uint64_t bitIndex) const
Check if single bit is set.
Definition bitfield.h:156
TYPE bits[size]
Definition bitfield.h:93
constexpr bool IsSet() const
Check if single bit is set.
Definition bitfield.h:170
static constexpr BitField< NUMBITS > Or(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to OR combination
Definition bitfield.h:279
static const int size
Definition bitfield.h:71
#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 SetBit(uint64 mask, uint8 bit)
Definition bit.h:21
uint16_t T
Definition bitfield.h:80
uint32_t T
Definition bitfield.h:84
uint64_t T
Definition bitfield.h:88
uint8_t T
Definition bitfield.h:76
int IndexT
Definition types.h:48