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

Changed to single alloc

This commit is contained in:
Brian Fiete 2020-02-13 07:53:32 -08:00
parent 2d3518dcd4
commit 468b5e292d

View file

@ -257,10 +257,12 @@ private:
void Resize(intptr newSize, bool forceNewHashCodes)
{
BF_ASSERT(newSize >= mAllocSize);
int_cosize* newBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * newSize);
Entry* newEntries;
int_cosize* newBuckets;
AllocData(newSize, newEntries, newBuckets);
for (int_cosize i = 0; i < newSize; i++)
newBuckets[i] = -1;
Entry* newEntries = (Entry*)this->rawAllocate(sizeof(Entry)*newSize);
for (int i = 0; i < mCount; i++)
{
@ -294,8 +296,7 @@ private:
}
}
this->rawDeallocate(mBuckets);
this->rawDeallocate(mEntries);
DeleteData();
mBuckets = newBuckets;
mEntries = newEntries;
@ -332,10 +333,10 @@ private:
void Initialize(intptr capacity)
{
int_cosize size = GetPrimeish((int_cosize)capacity);
mBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * size);
AllocData(size, mEntries, mBuckets);
mAllocSize = size;
for (int_cosize i = 0; i < (int_cosize)mAllocSize; i++) mBuckets[i] = -1;
mEntries = (Entry*)this->rawAllocate(sizeof(Entry) * size);
mFreeList = -1;
}
@ -431,8 +432,7 @@ public:
}
else
{
mBuckets = (int_cosize*)this->rawAllocate(sizeof(int_cosize) * mAllocSize);
mEntries = (Entry*)this->rawAllocate(sizeof(Entry) * mAllocSize);
AllocData(mAllocSize, mEntries, mBuckets);
for (int_cosize i = 0; i < mAllocSize; i++)
mBuckets[i] = val.mBuckets[i];
@ -465,6 +465,18 @@ public:
mFreeList = val.mFreeList;
}
void AllocData(intptr size, Entry*& outEntries, int_cosize*& outBuckets)
{
uint8* data = (uint8*)this->rawAllocate(size * (sizeof(Entry) + sizeof(int_cosize)));
outEntries = (Entry*)data;
outBuckets = (int_cosize*)(data + size * sizeof(Entry));
}
void DeleteData()
{
this->rawDeallocate(mEntries);
}
~HashSet()
{
if (!std::is_pod<TKey>::value)
@ -476,8 +488,7 @@ public:
}
}
this->rawDeallocate(mBuckets);
this->rawDeallocate(mEntries);
DeleteData();
}
HashSet& operator=(const HashSet& rhs)