rename src to utils
This commit is contained in:
49
utils/lists/gryphn_array_list.h
Normal file
49
utils/lists/gryphn_array_list.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "stdlib.h"
|
||||
|
||||
typedef struct gnArrayList {
|
||||
int count;
|
||||
int maxCount;
|
||||
void* data;
|
||||
} gnArrayList;
|
||||
|
||||
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 gnArrayList gnCreateArrayList(int count) {
|
||||
gnArrayList newList;
|
||||
|
||||
if (count == 0) {
|
||||
|
||||
} else {
|
||||
newList.count = count;
|
||||
newList.maxCount = count;
|
||||
newList.data = malloc(sizeof(void*) * count);
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
inline void gnArrayListResize(gnArrayList* 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 gnArrayListReserve(gnArrayList* 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);
|
||||
}
|
22
utils/lists/gryphn_linked_list.h
Normal file
22
utils/lists/gryphn_linked_list.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "stdlib.h"
|
||||
|
||||
// why would one use a linked list
|
||||
typedef struct gnLinkedList {
|
||||
void* data;
|
||||
gnLinkedList* nextNode;
|
||||
} gnLinkedList;
|
||||
|
||||
static gnLinkedList gnCreateLinkedList(int count) {
|
||||
gnLinkedList list;
|
||||
|
||||
gnLinkedList* currentNode = &list;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if ((i + 1) < count) {
|
||||
currentNode->nextNode = (gnLinkedList*)malloc(sizeof(gnLinkedList));
|
||||
currentNode = currentNode->nextNode;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
Reference in New Issue
Block a user