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