From 031cc2c5afc4fa93f9e12a33cbd1af200cc4628a Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Sun, 2 Apr 2023 12:15:36 +0200 Subject: [PATCH] Use core/linked_list.h --- base.cpp | 103 --------------------------------------- base_data_structures.cpp | 3 +- 2 files changed, 2 insertions(+), 104 deletions(-) diff --git a/base.cpp b/base.cpp index 523db1a..3949b44 100644 --- a/base.cpp +++ b/base.cpp @@ -335,108 +335,5 @@ operator!=(Intern_String a, Intern_String b) { return !result; } -//----------------------------------------------------------------------------- -// Very cool macros. Since these are macros it's recommended to wrap them -// in a function and not use directly -//----- ----------------------------------------------------------------------- -#define SLL_QUEUE_ADD_MOD(f, l, n, next) \ - do { \ - if ((f) == 0) { \ - (f) = (l) = (n); \ - } \ - else { \ - (l) = (l)->next = (n); \ - } \ - } while (0) -#define SLL_QUEUE_ADD(f, l, n) SLL_QUEUE_ADD_MOD(f, l, n, next) - -#define SLL_QUEUE_POP_FIRST_MOD(f, l, next) \ - do { \ - if ((f) == (l)) { \ - (f) = (l) = 0; \ - } \ - else { \ - (f) = (f)->next; \ - } \ - } while (0) -#define SLL_QUEUE_POP_FIRST(f, l) SLL_QUEUE_POP_FIRST_MOD(f, l, next) - -#define SLL_STACK_ADD_MOD(stack_base, new_stack_base, next) \ - do { \ - (new_stack_base)->next = (stack_base); \ - (stack_base) = (new_stack_base); \ - } while (0) -#define SLL_STACK_ADD(stack_base, new_stack_base) SLL_STACK_ADD_MOD(stack_base, new_stack_base, next) - -#define SLL_STACK_POP(stack_base) \ - do { \ - if (stack_base) { \ - auto(N) = (stack_base); \ - (stack_base) = (stack_base)->next; \ - (N)->next = 0; \ - } \ - } while (0) - -#define DLL_QUEUE_ADD_LAST_MOD(f, l, node, next, prev) \ - do { \ - if ((f) == 0) { \ - (f) = (l) = (node); \ - (node)->prev = 0; \ - (node)->next = 0; \ - } \ - else { \ - (l)->next = (node); \ - (node)->prev = (l); \ - (node)->next = 0; \ - (l) = (node); \ - } \ - } while (0) -#define DLL_QUEUE_ADD_LAST(f, l, node) DLL_QUEUE_ADD_LAST_MOD(f, l, node, next, prev) -#define DLL_QUEUE_ADD(f, l, node) DLL_QUEUE_ADD_LAST(f, l, node) -#define DLL_QUEUE_REMOVE_MOD(first, last, node, next, prev) \ - do { \ - if ((first) == (last)) { \ - assert_message((node) == (first), "Macro assert failed"); \ - (first) = (last) = 0; \ - } \ - else if ((last) == (node)) { \ - (last) = (last)->prev; \ - (last)->next = 0; \ - } \ - else if ((first) == (node)) { \ - (first) = (first)->next; \ - (first)->prev = 0; \ - } \ - else { \ - (node)->prev->next = (node)->next; \ - (node)->next->prev = (node)->prev; \ - } \ - } while (0) -#define DLL_QUEUE_REMOVE(first, last, node) DLL_QUEUE_REMOVE_MOD(first, last, node, next, prev) - -#define DLL_STACK_ADD_MOD(first, node, next, prev) \ - do { \ - (node)->next = (first); \ - if ((first)) \ - (first)->prev = (node); \ - (first) = (node); \ - (node)->prev = 0; \ - } while (0) -#define DLL_STACK_ADD(first, node) DLL_STACK_ADD_MOD(first, node, next, prev) -#define DLL_STACK_REMOVE_MOD(first, node, next, prev) \ - do { \ - if ((node) == (first)) { \ - (first) = (first)->next; \ - if ((first)) \ - (first)->prev = 0; \ - } \ - else { \ - (node)->prev->next = (node)->next; \ - if ((node)->next) \ - (node)->next->prev = (node)->prev; \ - } \ - } while (0) -#define DLL_STACK_REMOVE(first, node) DLL_STACK_REMOVE_MOD(first, node, next, prev) - #define For_Linked_List_Named(a, it) for (auto *it = (a); it; it = it->next) // @todo: reference? #define For_Linked_List(a) For_Linked_List_Named(a, it) diff --git a/base_data_structures.cpp b/base_data_structures.cpp index a77c825..834e20c 100644 --- a/base_data_structures.cpp +++ b/base_data_structures.cpp @@ -4,6 +4,7 @@ #define ARRAY_ALLOCATE(allocator, size) allocate_size(allocator, size) #define ARRAY_DEALLOCATE(allocator, p) deallocate(allocator, p) #include "core/array.hpp" +#include "core/linked_list.h" //----------------------------------------------------------------------------- // Map @@ -291,7 +292,7 @@ void list_make_sure_there_is_room_for_item_count(Allocator *arena, List *list } assert(node); - DLL_QUEUE_ADD_LAST(list->first, list->last, node); + DLL_QUEUE_ADD(list->first, list->last, node); } }