1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed some comptime dependency rebuilding issues with aliases/extensions

This commit is contained in:
Brian Fiete 2022-02-16 18:28:23 -05:00
parent 1cd198cea9
commit 434a7406de
22 changed files with 394 additions and 86 deletions

View file

@ -4,28 +4,43 @@
NS_BF_BEGIN;
#define BF_BITSET_ELEM_SIZE (sizeof(uintptr)*8)
#define BF_BITSET_ELEM_BITCOUNT (sizeof(uintptr)*8)
class BitSet
{
public:
uintptr* mBits;
int mNumInts;
int mNumBits;
public:
BitSet()
{
mNumInts = 0;
mNumBits = 0;
mBits = NULL;
}
BitSet(int numBits)
{
mNumInts = 0;
mNumBits = 0;
mBits = NULL;
this->Resize(numBits);
}
BitSet(BitSet&& other)
{
mNumBits = other.mNumBits;
mBits = other.mBits;
other.mNumBits = 0;
other.mBits = NULL;
}
BitSet(const BitSet& other)
{
mNumBits = 0;
mBits = NULL;
*this = other;
}
~BitSet()
{
delete this->mBits;
@ -33,28 +48,68 @@ public:
void Resize(int numBits)
{
int numInts = (numBits + BF_BITSET_ELEM_SIZE - 1) / BF_BITSET_ELEM_SIZE;
if (numInts == mNumInts)
return;
this->mNumInts = numInts;
int numInts = (numBits + BF_BITSET_ELEM_BITCOUNT - 1) / BF_BITSET_ELEM_BITCOUNT;
int curNumInts = (mNumBits + BF_BITSET_ELEM_BITCOUNT - 1) / BF_BITSET_ELEM_BITCOUNT;
mNumBits = numBits;
if (numInts == curNumInts)
return;
this->mNumBits = numBits;
delete this->mBits;
this->mBits = new uintptr[numInts];
memset(this->mBits, 0, numInts * sizeof(uintptr));
}
bool IsSet(int idx)
void Clear()
{
return (this->mBits[idx / BF_BITSET_ELEM_SIZE] & ((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE))) != 0;
int curNumInts = (mNumBits + BF_BITSET_ELEM_BITCOUNT - 1) / BF_BITSET_ELEM_BITCOUNT;
memset(mBits, 0, curNumInts * sizeof(uintptr));
}
bool IsSet(int idx) const
{
BF_ASSERT((uintptr)idx < (uintptr)mNumBits);
return (this->mBits[idx / BF_BITSET_ELEM_BITCOUNT] & ((uintptr)1 << (idx % BF_BITSET_ELEM_BITCOUNT))) != 0;
}
void Set(int idx)
{
this->mBits[idx / BF_BITSET_ELEM_SIZE] |= ((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE));
BF_ASSERT((uintptr)idx < (uintptr)mNumBits);
this->mBits[idx / BF_BITSET_ELEM_BITCOUNT] |= ((uintptr)1 << (idx % BF_BITSET_ELEM_BITCOUNT));
}
void Clear(int idx)
{
this->mBits[idx / BF_BITSET_ELEM_SIZE] &= ~((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE));
BF_ASSERT((uintptr)idx < (uintptr)mNumBits);
this->mBits[idx / BF_BITSET_ELEM_BITCOUNT] &= ~((uintptr)1 << (idx % BF_BITSET_ELEM_BITCOUNT));
}
bool IsEmpty()
{
return mNumBits == 0;
}
bool operator==(const BitSet& other) const
{
int curNumInts = (mNumBits + BF_BITSET_ELEM_BITCOUNT - 1) / BF_BITSET_ELEM_BITCOUNT;
if (mNumBits != other.mNumBits)
return false;
for (int i = 0; i < curNumInts; i++)
if (mBits[i] != other.mBits[i])
return false;
return true;
}
bool operator!=(const BitSet& other) const
{
return !(*this == other);
}
BitSet& operator=(const BitSet& other)
{
Resize(other.mNumBits);
int curNumInts = (mNumBits + BF_BITSET_ELEM_BITCOUNT - 1) / BF_BITSET_ELEM_BITCOUNT;
memcpy(mBits, other.mBits, curNumInts * sizeof(uintptr));
return *this;
}
};