1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Linux fixes

This commit is contained in:
Brian Fiete 2019-11-07 16:18:05 -08:00
parent 810c7b843b
commit 305d61f083

View file

@ -13,12 +13,12 @@ private:
if (childIdx > 0) if (childIdx > 0)
{ {
int32 parentIdx = (childIdx - 1) / 2; int32 parentIdx = (childIdx - 1) / 2;
if (mVals[childIdx] > mVals[parentIdx]) if (this->mVals[childIdx] > this->mVals[parentIdx])
{ {
// swap parent and child // swap parent and child
T t = mVals[parentIdx]; T t = this->mVals[parentIdx];
mVals[parentIdx] = mVals[childIdx]; this->mVals[parentIdx] = this->mVals[childIdx];
mVals[childIdx] = t; this->mVals[childIdx] = t;
HeapifyUp(parentIdx); HeapifyUp(parentIdx);
} }
} }
@ -30,25 +30,25 @@ private:
int32 leftChildIdx = 2 * parentIdx + 1; int32 leftChildIdx = 2 * parentIdx + 1;
int32 rightChildIdx = leftChildIdx + 1; int32 rightChildIdx = leftChildIdx + 1;
int32 largestChildIdx = parentIdx; int32 largestChildIdx = parentIdx;
if (leftChildIdx < mSize && mVals[leftChildIdx] > mVals[largestChildIdx]) if (leftChildIdx < this->mSize && this->mVals[leftChildIdx] > this->Vals[largestChildIdx])
{ {
largestChildIdx = leftChildIdx; largestChildIdx = leftChildIdx;
} }
if (rightChildIdx < mSize && mVals[rightChildIdx] > mVals[largestChildIdx]) if (rightChildIdx < this->mSize && this->mVals[rightChildIdx] > this->mVals[largestChildIdx])
{ {
largestChildIdx = rightChildIdx; largestChildIdx = rightChildIdx;
} }
if (largestChildIdx != parentIdx) if (largestChildIdx != parentIdx)
{ {
T t = mVals[parentIdx]; T t = this->mVals[parentIdx];
mVals[parentIdx] = mVals[largestChildIdx]; this->mVals[parentIdx] = this->mVals[largestChildIdx];
mVals[largestChildIdx] = t; this->mVals[largestChildIdx] = t;
HeapifyDown(largestChildIdx); HeapifyDown(largestChildIdx);
} }
} }
public: public:
BinaryMaxHeap() : Array() BinaryMaxHeap() : Array<T>()
{ {
} }
@ -56,22 +56,22 @@ public:
/// Add an item to the heap /// Add an item to the heap
void Add(T item) void Add(T item)
{ {
Array::Add(item); Array<T>::Add(item);
HeapifyUp(mSize - 1); HeapifyUp(this->mSize - 1);
} }
/// Get the item of the root /// Get the item of the root
T Peek() T Peek()
{ {
return mVals[0]; return this->mVals[0];
} }
/// Extract the item of the root /// Extract the item of the root
T Pop() T Pop()
{ {
T item = mVals[0]; T item = this->mVals[0];
mSize--; this->mSize--;
mVals[0] = mVals[mSize]; this->mVals[0] = this->mVals[this->mSize];
HeapifyDown(0); HeapifyDown(0);
return item; return item;
} }
@ -86,12 +86,12 @@ private:
if (childIdx > 0) if (childIdx > 0)
{ {
int32 parentIdx = (childIdx - 1) / 2; int32 parentIdx = (childIdx - 1) / 2;
if (mVals[childIdx] < mVals[parentIdx]) if (this->mVals[childIdx] < this->mVals[parentIdx])
{ {
// swap parent and child // swap parent and child
T t = mVals[parentIdx]; T t = this->mVals[parentIdx];
mVals[parentIdx] = mVals[childIdx]; this->mVals[parentIdx] = this->mVals[childIdx];
mVals[childIdx] = t; this->mVals[childIdx] = t;
HeapifyUp(parentIdx); HeapifyUp(parentIdx);
} }
} }
@ -103,25 +103,25 @@ private:
int32 leftChildIdx = 2 * parentIdx + 1; int32 leftChildIdx = 2 * parentIdx + 1;
int32 rightChildIdx = leftChildIdx + 1; int32 rightChildIdx = leftChildIdx + 1;
int32 largestChildIdx = parentIdx; int32 largestChildIdx = parentIdx;
if (leftChildIdx < mSize && mVals[leftChildIdx] < mVals[largestChildIdx]) if (leftChildIdx < this->mSize && this->mVals[leftChildIdx] < this->mVals[largestChildIdx])
{ {
largestChildIdx = leftChildIdx; largestChildIdx = leftChildIdx;
} }
if (rightChildIdx < mSize && mVals[rightChildIdx] < mVals[largestChildIdx]) if (rightChildIdx < this->mSize && this->mVals[rightChildIdx] < this->mVals[largestChildIdx])
{ {
largestChildIdx = rightChildIdx; largestChildIdx = rightChildIdx;
} }
if (largestChildIdx != parentIdx) if (largestChildIdx != parentIdx)
{ {
T t = mVals[parentIdx]; T t = this->mVals[parentIdx];
mVals[parentIdx] = mVals[largestChildIdx]; this->mVals[parentIdx] = this->mVals[largestChildIdx];
mVals[largestChildIdx] = t; this->mVals[largestChildIdx] = t;
HeapifyDown(largestChildIdx); HeapifyDown(largestChildIdx);
} }
} }
public: public:
BinaryMinHeap() : Array() BinaryMinHeap() : Array<T>()
{ {
} }
@ -129,22 +129,22 @@ public:
/// Add an item to the heap /// Add an item to the heap
void Add(T item) void Add(T item)
{ {
Array::Add(item); Array<T>::Add(item);
HeapifyUp(mSize - 1); HeapifyUp(this->mSize - 1);
} }
/// Get the item of the root /// Get the item of the root
T Peek() T Peek()
{ {
return mVals[0]; return this->mVals[0];
} }
/// Extract the item of the root /// Extract the item of the root
T Pop() T Pop()
{ {
T item = mVals[0]; T item = this->mVals[0];
mSize--; this->mSize--;
mVals[0] = mVals[mSize]; this->mVals[0] = this->mVals[this->mSize];
HeapifyDown(0); HeapifyDown(0);
return item; return item;
} }