Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions include/hx/QuickVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace hx
template<typename T>
struct QuickVec
{
int mAlloc;
int mSize;
size_t mAlloc;
size_t mSize;
T *mPtr;

QuickVec() : mPtr(0), mAlloc(0), mSize(0) { }
Expand All @@ -26,7 +26,7 @@ struct QuickVec
if (mSize+1>mAlloc)
{
mAlloc = 10 + (mSize*3/2);
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
}
mPtr[mSize]=inT;
mSize++;
Expand All @@ -37,31 +37,31 @@ struct QuickVec
std::swap(mSize, inOther.mSize);
std::swap(mPtr, inOther.mPtr);
}
T *setSize(int inSize)
T *setSize(size_t inSize)
{
if (inSize>mAlloc)
{
mAlloc = inSize;
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
}
mSize = inSize;
return mPtr;
}
// Can push this many without realloc
bool hasExtraCapacity(int inN)
bool hasExtraCapacity(size_t inN)
{
return mSize+inN<=mAlloc;
}

bool safeReserveExtra(int inN)
bool safeReserveExtra(size_t inN)
{
int want = mSize + inN;
size_t want{ mSize + inN };
if (want>mAlloc)
{
int wantAlloc = 10 + (mSize*3/2);
size_t wantAlloc{ 10 + (mSize * 3 / 2) };
if (wantAlloc<want)
wantAlloc = want;
T *newBuffer = (T *)malloc( sizeof(T)*wantAlloc );
T *newBuffer = static_cast<T*>(malloc( sizeof(T)*wantAlloc ));
if (!newBuffer)
return false;
mAlloc = wantAlloc;
Expand All @@ -80,12 +80,12 @@ struct QuickVec
{
return mPtr[--mSize];
}
inline void qerase(int inPos)
inline void qerase(size_t inPos)
{
--mSize;
mPtr[inPos] = mPtr[mSize];
}
inline void erase(int inPos)
inline void erase(size_t inPos)
{
--mSize;
if (mSize>inPos)
Expand All @@ -95,31 +95,33 @@ struct QuickVec

inline bool qerase_val(T inVal)
{
for(int i=0;i<mSize;i++)
if (mPtr[i]==inVal)
for (size_t i{ 0 }; i < mSize; i++)
{
if (mPtr[i] == inVal)
{
--mSize;
mPtr[i] = mPtr[mSize];
return true;
}
}
Comment thread
Aidan63 marked this conversation as resolved.
return false;
}

inline bool some_left() { return mSize; }
inline bool empty() const { return !mSize; }
inline void clear() { mSize = 0; }
inline int next()
inline size_t next()
{
if (mSize+1>=mAlloc)
{
mAlloc = 10 + (mSize*3/2);
mPtr = (T *)realloc(mPtr,sizeof(T)*mAlloc);
mPtr = static_cast<T*>(realloc(mPtr,sizeof(T)*mAlloc));
}
return mSize++;
}
inline int size() const { return mSize; }
inline T &operator[](int inIndex) { return mPtr[inIndex]; }
inline const T &operator[](int inIndex) const { return mPtr[inIndex]; }
inline size_t size() const { return mSize; }
inline T &operator[](size_t inIndex) { return mPtr[inIndex]; }
inline const T &operator[](size_t inIndex) const { return mPtr[inIndex]; }

private:
QuickVec(const QuickVec<T> &);
Expand All @@ -138,8 +140,8 @@ class QuickDeque
QuickVec<Slab *> mSpare;
QuickVec<Slab *> mActive;

int mHeadPos;
int mTailPos;
size_t mHeadPos;
size_t mTailPos;
Slab *mHead;
Slab *mTail;

Expand All @@ -153,9 +155,9 @@ class QuickDeque
}
~QuickDeque()
{
for(int i=0;i<mSpare.size();i++)
for (size_t i{0}; i < mSpare.size(); i++)
delete mSpare[i];
for(int i=0;i<mActive.size();i++)
for (size_t i{0}; i < mActive.size(); i++)
delete mActive[i];
delete mHead;
if (mTail!=mHead)
Expand Down
Loading
Loading