// // Created by stefan on 10.06.20. // #include "arena_list.h" Node *listPopFront(List *list) { Node *front = list->first; if (front == NULL) { return NULL; } list->first = front->next; if (front == list->last) { // Only Node in the list list->last = NULL; return front; } if (front->next != NULL) { list->first->prev = NULL; front->next = NULL; } return front; } Node *listPopBack(List list) { return NULL; } void listPushFront(List *list, Node *new) { if (list->first == NULL) { // List was empty list->first = new; list->last = new; return; } new->next = list->first; new->next->prev = new; list->first = new; } void listPushBack(List list, Node *value) {} ArenaList alInit(Node *arena, size_t size) { ArenaList al; al.activeList = (List){.first = NULL, .last = NULL}; al.freeList = (List){.first = arena, .last = &arena[size - 1]}; arena[0] = (Node){.value = NULL, .prev = NULL, .next = &arena[1]}; for (size_t i = 1; i < size - 1; ++i) { arena[i] = (Node){.value = NULL, .prev = &arena[i - 1], .next = &arena[i + 1]}; } arena[size - 1] = (Node){.value = NULL, .prev = &arena[size - 2], .next = NULL}; return al; } int alPush(ArenaList* al, void *value) { Node *current = listPopFront(&al->freeList); // List is empty if (current == NULL) { return -1; } current->value = value; listPushFront(&al->activeList, current); return 0; }