Linked List
Added in the first support for a linked list type. It is called a List type in the library. Have tested the functionality and so far all seems good
This commit is contained in:
@@ -1,55 +1,60 @@
|
||||
#include "types/linked_list.h"
|
||||
#include <defines.h>
|
||||
#include <logger/logger.h>
|
||||
#include <memory/zone.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Size of i16: %" PRId16 "\n", sizeof(i16));
|
||||
printf("Size of u16: %" PRIu16 "\n", sizeof(u16));
|
||||
printf("Size of i32: %" PRId32 "\n", sizeof(i32));
|
||||
printf("Size of u32: %" PRIu32 "\n", sizeof(u32));
|
||||
printf("Size of i64: %" PRId64 "\n", sizeof(i64));
|
||||
printf("Size of u64: %" PRIu64 "\n", sizeof(u64));
|
||||
printf("Size of f32: %lu\n", sizeof(f32));
|
||||
printf("Size of f64: %lu\n", sizeof(f64));
|
||||
QINFO("Size of i16: %" PRId16, sizeof(i16));
|
||||
QINFO("Size of u16: %" PRIu16, sizeof(u16));
|
||||
QINFO("Size of i32: %" PRId32, sizeof(i32));
|
||||
QINFO("Size of u32: %" PRIu32, sizeof(u32));
|
||||
QINFO("Size of i64: %" PRId64, sizeof(i64));
|
||||
QINFO("Size of u64: %" PRIu64, sizeof(u64));
|
||||
QINFO("Size of f32: %lu", sizeof(f32));
|
||||
QINFO("Size of f64: %lu", sizeof(f64));
|
||||
|
||||
QFATAL("Test");
|
||||
QERROR("Test");
|
||||
QWARN("Test");
|
||||
QINFO("Test");
|
||||
QDEBUG("Test");
|
||||
QINFO("Creating a List...");
|
||||
List my_list = listCreate();
|
||||
QINFO("Pushing to my_list...")
|
||||
i32 pushVal = 42;
|
||||
listPush(&my_list, &pushVal);
|
||||
i32 peekVal = *(i32 *)listPeek(&my_list);
|
||||
|
||||
printf("\nCreating new zone 4K in size...\n");
|
||||
Zone *test_zone = zoneCreate(4096);
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
void *test_alloc = zoneAlloc(test_zone, 4);
|
||||
void *test_alloc2 = zoneAlloc(test_zone, 4);
|
||||
QINFO("Pushing another number to my_list...");
|
||||
i32 pushVal2 = 169420;
|
||||
listPush(&my_list, &pushVal2);
|
||||
peekVal = *(i32 *)listPeek(&my_list);
|
||||
|
||||
printf("Address of test_zone: %p\n", (void *)test_zone);
|
||||
printf("Address of test_alloc: %p\n", test_alloc);
|
||||
printf("Address of test_alloc2: %p\n\n", test_alloc2);
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
zoneClear(test_zone);
|
||||
i32 pushVal3 = 69;
|
||||
listPush(&my_list, &pushVal3);
|
||||
QDEBUG("Peeking a 3rd value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
u64 *test_free = zoneAlloc(test_zone, sizeof(u64));
|
||||
i32 popVal = *(i32 *)listPop(&my_list);
|
||||
QDEBUG("Popped a value off of my_list: %" PRId32, popVal);
|
||||
|
||||
printf("Address of test_free: %p\n", (void *)test_free);
|
||||
printf("Freeing test_free...\n");
|
||||
peekVal = *(i32 *)listPeek(&my_list);
|
||||
|
||||
zoneFree(&test_free, sizeof(u64));
|
||||
QDEBUG("Peeking value off of my_list: %" PRId32, peekVal);
|
||||
|
||||
printf("Is test_free NULL: %s\n\n", test_free == NULL ? "true" : "false");
|
||||
i32 insertValue = 80085;
|
||||
|
||||
zoneDestroy(test_zone);
|
||||
QINFO("Inserting a value at position 2.");
|
||||
listInsertAt(&my_list, 2, &insertValue);
|
||||
|
||||
const u64 FOUR_GIGS = (u64)4 * 1024 * 1024 * 1024;
|
||||
QDEBUG("Data at position 2 is: %" PRId32, *(i32 *)listDataAt(&my_list, 2));
|
||||
|
||||
Zone *break_zone = zoneCreate(FOUR_GIGS);
|
||||
QINFO("Removing a value at position 2.");
|
||||
listRemoveAt(&my_list, 2);
|
||||
|
||||
while (zoneAlloc(break_zone, 1024 * 1024 * 1024) != NULL) {
|
||||
}
|
||||
QDEBUG("Data at position 2 is now: %" PRId32,
|
||||
*(i32 *)listDataAt(&my_list, 2));
|
||||
|
||||
zoneDestroy(break_zone);
|
||||
QINFO("Destorying List...");
|
||||
listDestroy(&my_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user