From 2372b6df37a01495716fa80bb1bf016d742b42d5 Mon Sep 17 00:00:00 2001 From: Greg Wells Date: Thu, 15 May 2025 18:43:59 -0400 Subject: [PATCH] create list files --- src/lists/gryphn_array_list.h | 49 ++++++++++++++++++++++++++++++++++ src/lists/gryphn_linked_list.h | 0 2 files changed, 49 insertions(+) create mode 100644 src/lists/gryphn_array_list.h create mode 100644 src/lists/gryphn_linked_list.h diff --git a/src/lists/gryphn_array_list.h b/src/lists/gryphn_array_list.h new file mode 100644 index 0000000..3c344ae --- /dev/null +++ b/src/lists/gryphn_array_list.h @@ -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); +} diff --git a/src/lists/gryphn_linked_list.h b/src/lists/gryphn_linked_list.h new file mode 100644 index 0000000..e69de29