44 static_assert(NUMBITS > 0);
50 constexpr BitField(std::initializer_list<unsigned int> list);
62 constexpr bool IsSet(
const uint64_t bitIndex)
const;
64 template <u
int64_t bitIndex>
constexpr bool IsSet()
const;
70 constexpr void SetBit(
const uint64_t bitIndex);
72 constexpr void SetBitIf(
const uint64_t bitIndex, uint64_t cond);
74 template <u
int64_t bitIndex>
constexpr void SetBit();
91 static constexpr uint64_t
BASE = NUMBITS > 32 ? 64 : NUMBITS > 16 ? 32 : NUMBITS > 8 ? 16 : 8;
102 return this->bits[index];
108 this->bits[index] = value;
118 for (i = 0; i <
size; i++)
134 for (
auto bit : list)
143template<
unsigned int NUMBITS>
146 for (
IndexT i = 0; i < NUMBITS; i++)
148 if (mask & (1ull << i))
158template <
unsigned int NUMBITS>
175template <
unsigned int NUMBITS>
179 return !(*
this == rhs);
185template <
unsigned int NUMBITS>
190 const TYPE i = (1ull << (bitIndex %
BASE));
192 return (this->
bits[index] & i) == i;
198template <
unsigned int NUMBITS>
199template <u
int64_t bitIndex>
203 static_assert(bitIndex < NUMBITS);
204 constexpr TYPE i = (1ull << (bitIndex %
BASE));
205 constexpr TYPE index = bitIndex /
BASE;
206 return (this->
bits[index] & i) == i;
212template <
unsigned int NUMBITS>
217 for (i = 0; i <
size; i++)
226template <
unsigned int NUMBITS>
231 for (i = 0; i <
size; i++)
233 if (this->
bits[i] != 0)
244template <
unsigned int NUMBITS>
250 const TYPE bit = (1ull << (i %
BASE));
251 this->
bits[index] |= bit;
257template <
unsigned int NUMBITS>
263 const TYPE bit = (1ull << (i %
BASE));
264 this->
bits[index] |= bit * cond;
270template <
unsigned int NUMBITS>
275 static_assert(i < NUMBITS);
277 constexpr TYPE bit = (1ull << (i %
BASE));
278 this->
bits[index] |= bit;
284template <
unsigned int NUMBITS>
290 const TYPE bit = ~(1ull << (i %
BASE));
291 this->
bits[index] &= bit;
297template <
unsigned int NUMBITS>
302 return this->
bits[section] == 0;
308template <
unsigned int NUMBITS>
323template <
unsigned int NUMBITS>
Implements large bit field.
Definition bitfield.h:43
constexpr bool operator==(const BitField< NUMBITS > &rhs) const
equality operator
Definition bitfield.h:160
static constexpr uint64_t BASE
Definition bitfield.h:91
void ClearBit(const uint64_t bitIndex)
clear a bit by index
Definition bitfield.h:286
BitFieldBitType< BASE >::T GetBits(size_t index) const
Definition bitfield.h:99
constexpr bool operator!=(const BitField< NUMBITS > &rhs) const
inequality operator
Definition bitfield.h:177
BitField(const BitField< NUMBITS > &rhs)=default
copy constructor
bool IsNull() const
return true if all bits are 0
Definition bitfield.h:228
constexpr void SetBit()
set a bit by index
Definition bitfield.h:273
BitField(const uint64_t mask)
Construct from mask.
Definition bitfield.h:144
bool SectionIsNull(uint64_t section) const
Check if a section of the bitfield is set.
Definition bitfield.h:299
static constexpr BitField< NUMBITS > And(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to AND combination
Definition bitfield.h:325
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:259
constexpr void SetBit(const uint64_t bitIndex)
set a bit by index
Definition bitfield.h:246
constexpr BitField(std::initializer_list< unsigned int > list)
constructs a bitfield based on multiple values
Definition bitfield.h:127
typename BitFieldBitType< BASE >::T TYPE
Definition bitfield.h:94
void Clear()
clear content
Definition bitfield.h:214
BitField()
constructor
Definition bitfield.h:115
constexpr bool IsSet(const uint64_t bitIndex) const
Check if single bit is set.
Definition bitfield.h:187
TYPE bits[size]
Definition bitfield.h:96
constexpr bool IsSet() const
Check if single bit is set.
Definition bitfield.h:201
static constexpr BitField< NUMBITS > Or(const BitField< NUMBITS > &b0, const BitField< NUMBITS > &b1)
set bitfield to OR combination
Definition bitfield.h:310
void SetBits(size_t index, typename BitFieldBitType< BASE >::T value)
Definition bitfield.h:105
static const int size
Definition bitfield.h:92
#define n_assert(exp)
Definition debug.h:58
A quad tree designed to return regions of free 2D space.
Definition Random.cs:5
uint16_t T
Definition bitfield.h:31
uint32_t T
Definition bitfield.h:35
uint64_t T
Definition bitfield.h:39
uint8_t T
Definition bitfield.h:27
int IndexT
Definition types.h:49