28class ResizeableArray {
30 ResizeableArray(int32_t newElementSize, int32_t newMaxNumEmptySpacesToKeep = 16,
31 int32_t newNumExtrarSpacesToAllocate = 15);
34 bool cloneFrom(ResizeableArray
const* other);
36 void swapStateWith(ResizeableArray* other);
37 void deleteAtIndex(int32_t i, int32_t numToDelete = 1,
bool mayShortenMemoryAfter =
true);
38 bool ensureEnoughSpaceAllocated(int32_t numAdditionalElementsNeeded);
39 Error insertAtIndex(int32_t i, int32_t numToInsert = 1,
void* thingNotToStealFrom =
nullptr);
40 void swapElements(int32_t i1, int32_t i2);
41 void repositionElement(int32_t iFrom, int32_t iTo);
43 void setMemory(
void* newMemory, int32_t newMemorySize);
44 void setStaticMemory(
void* newMemory, int32_t newMemorySize);
46 void moveElementsLeft(int32_t oldStartIndex, int32_t oldStopIndex, int32_t distance);
47 void moveElementsRight(int32_t oldStartIndex, int32_t oldStopIndex, int32_t distance);
49 [[gnu::always_inline]]
inline void* getElementAddress(int32_t index) {
50 int32_t absoluteIndex = index + memoryStart;
51 if (absoluteIndex >= memorySize)
52 absoluteIndex -= memorySize;
53 return (
char* __restrict__)memory + (absoluteIndex * elementSize);
56 [[gnu::always_inline]]
inline int32_t getNumElements() {
return numElements; }
59 bool emptyingShouldFreeMemory;
60 uint32_t staticMemoryAllocationSize;
71#if RESIZEABLE_ARRAY_DO_LOCKS
78 void attemptMemoryShorten();
79 bool attemptMemoryExpansion(int32_t minNumToExtend, int32_t idealNumToExtend,
bool mayExtendAllocation,
80 void* thingNotToStealFrom);
81 void copyToNewMemory(
void* newMemory, uint32_t destinationIndex,
void* source, uint32_t numElementsToCopy,
82 uint32_t newMemorySize, uint32_t newMemoryStartIndex);
83 Error copyElementsFromOldMemory(
void* otherMemory, int32_t otherMemorySize, int32_t otherMemoryStart);
85 void moveElementsRightNoWrap(int32_t oldStartIndex, int32_t oldStopIndex, int32_t distance);
86 void moveElementsLeftNoWrap(int32_t oldStartIndex, int32_t oldStopIndex, int32_t distance);
88 void* memoryAllocationStart;
90 const int32_t maxNumEmptySpacesToKeep;
91 const int32_t numExtraSpacesToAllocate;