create list files

This commit is contained in:
Greg Wells
2025-05-15 18:43:59 -04:00
parent 7ae504d952
commit 2372b6df37
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#pragma once
#include "stdlib.h"
typedef struct gnCList {
int count;
int maxCount;
void* data;
} gnCList;
const int GROWTH_RATE = 2; // i heard somewhere that 1.5 is better but imma use 2 because I also heard that its better somewhere else
inline gnCList gnCreateCList(int count) {
gnCList newList;
if (count == 0) {
} else {
newList.count = count;
newList.maxCount = count;
newList.data = malloc(sizeof(void*) * count);
}
return newList;
}
inline void gnCListResize(gnCList* cList, int count) {
cList->count = count;
while (cList->count > cList->maxCount) {
int oldMaxCount = cList->maxCount;
cList->maxCount *= GROWTH_RATE;
if (cList->count == oldMaxCount) {
cList->maxCount += 1;
}
}
cList->data = realloc(cList->data, cList->maxCount);
}
inline void gnCListReserve(gnCList* cList, int count) {
while (cList->count > cList->maxCount) {
int oldMaxCount = cList->maxCount;
cList->maxCount *= GROWTH_RATE;
if (cList->count == oldMaxCount) {
cList->maxCount += 1;
}
}
cList->data = realloc(cList->data, cList->maxCount);
}

View File