Fix BitArray again

This commit is contained in:
Wojtek Figat
2025-06-16 23:20:20 +02:00
parent 5a23060e05
commit eb6010cba7

View File

@@ -16,7 +16,6 @@ API_CLASS(InBuild) class BitArray
public: public:
using ItemType = uint64; using ItemType = uint64;
using AllocationData = typename AllocationType::template Data<ItemType>; using AllocationData = typename AllocationType::template Data<ItemType>;
static constexpr int32 ItemBitCount = 64;
private: private:
int32 _count; int32 _count;
@@ -210,8 +209,8 @@ public:
bool Get(const int32 index) const bool Get(const int32 index) const
{ {
ASSERT(index >= 0 && index < _count); ASSERT(index >= 0 && index < _count);
const ItemType offset = index / ItemBitCount; const ItemType offset = index / 64;
const ItemType bitMask = (ItemType)(1 << (index & (ItemBitCount - 1))); const ItemType bitMask = 1ull << (index & 63ull);
const ItemType item = ((ItemType*)_allocation.Get())[offset]; const ItemType item = ((ItemType*)_allocation.Get())[offset];
return (item & bitMask) != 0; return (item & bitMask) != 0;
} }
@@ -224,8 +223,8 @@ public:
void Set(const int32 index, const bool value) void Set(const int32 index, const bool value)
{ {
ASSERT(index >= 0 && index < _count); ASSERT(index >= 0 && index < _count);
const ItemType offset = index / ItemBitCount; const ItemType offset = index / 64;
const ItemType bitMask = (ItemType)(1 << (index & (ItemBitCount - 1))); const ItemType bitMask = 1ull << (index & 63ull);
ItemType& item = ((ItemType*)_allocation.Get())[offset]; ItemType& item = ((ItemType*)_allocation.Get())[offset];
if (value) if (value)
item |= bitMask; // Set the bit item |= bitMask; // Set the bit