mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 12:02:21 +02:00
61 lines
1,004 B
C
61 lines
1,004 B
C
![]() |
#pragma once
|
||
|
|
||
|
#include "BFPlatform.h"
|
||
|
|
||
|
NS_BF_BEGIN;
|
||
|
|
||
|
#define BF_BITSET_ELEM_SIZE (sizeof(uintptr)*8)
|
||
|
|
||
|
class BitSet
|
||
|
{
|
||
|
public:
|
||
|
uintptr* mBits;
|
||
|
int mNumInts;
|
||
|
|
||
|
public:
|
||
|
BitSet()
|
||
|
{
|
||
|
mNumInts = 0;
|
||
|
mBits = NULL;
|
||
|
}
|
||
|
|
||
|
BitSet(int numBits)
|
||
|
{
|
||
|
mNumInts = 0;
|
||
|
mBits = NULL;
|
||
|
this->Resize(numBits);
|
||
|
}
|
||
|
|
||
|
~BitSet()
|
||
|
{
|
||
|
delete this->mBits;
|
||
|
}
|
||
|
|
||
|
void Resize(int numBits)
|
||
|
{
|
||
|
int numInts = (numBits + BF_BITSET_ELEM_SIZE - 1) / BF_BITSET_ELEM_SIZE;
|
||
|
if (numInts == mNumInts)
|
||
|
return;
|
||
|
this->mNumInts = numInts;
|
||
|
delete this->mBits;
|
||
|
this->mBits = new uintptr[numInts];
|
||
|
memset(this->mBits, 0, numInts * sizeof(uintptr));
|
||
|
}
|
||
|
|
||
|
bool IsSet(int idx)
|
||
|
{
|
||
|
return (this->mBits[idx / BF_BITSET_ELEM_SIZE] & ((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE))) != 0;
|
||
|
}
|
||
|
|
||
|
void Set(int idx)
|
||
|
{
|
||
|
this->mBits[idx / BF_BITSET_ELEM_SIZE] |= ((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE));
|
||
|
}
|
||
|
|
||
|
void Clear(int idx)
|
||
|
{
|
||
|
this->mBits[idx / BF_BITSET_ELEM_SIZE] &= ~((uintptr)1 << (idx % BF_BITSET_ELEM_SIZE));
|
||
|
}
|
||
|
};
|
||
|
|
||
|
NS_BF_END;
|