From a229f9be8c4e9d8ede9429d9cd1b59c9fdd71332 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 5 May 2025 00:04:24 +0100 Subject: [PATCH] Run codegen on Linux --- src/primitives/array/array.c | 7546 +++++++++++++------------- src/primitives/array/array.h | 1010 ++-- src/primitives/dbl_list/dbl_list.c | 7902 ++++++++++++++-------------- src/primitives/dbl_list/dbl_list.h | 968 ++-- 4 files changed, 8713 insertions(+), 8713 deletions(-) diff --git a/src/primitives/array/array.c b/src/primitives/array/array.c index 474515f..a26512b 100644 --- a/src/primitives/array/array.c +++ b/src/primitives/array/array.c @@ -1,3773 +1,3773 @@ -/** - * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN - */ - -#include "./array.h" -#include "../mem_allocator/mem_allocator.h" -#include "../strings/str8/str8.h" -#include "../../common/misc/misc_utils.h" -#include "../../common/aliases/aliases.h" -#include "../../common/platform/platform.h" -#include -#include - -Str8 *wapp_str8_array_get(const Str8Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_str8_array_append_capped(Str8Array *array, Str8 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - Str8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_str8_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_str8_array_append_capped(array, *item); - } -} - -void wapp_str8_array_clear(Str8Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -Str8 wapp_str8_array_pop(Str8Array *array) { - if (!array || array->count == 0) { - return (Str8){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst) { - if (!src || !dst) { - return; - } - - wapp_str8_array_clear(dst); - - Str8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_str8_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_str8_array_append_capped(dst, *item); - } -} - -Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(Str8Array) + sizeof(Str8) * capacity; - Str8Array *array = NULL; - - if (!allocator) { - goto RETURN_STR8_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_STR8_ARRAY_ALLOC; - } - - array->items = (Str8 *)((u8 *)array + sizeof(Str8Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_STR8_ARRAY_ALLOC: - return array; -} - -Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item) { - Str8Array *output = array; - - if (!allocator || !array) { - goto RETURN_STR8_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_str8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_STR8_ARRAY_APPEND_ALLOC; - } - wapp_str8_array_copy_capped(array, output); - } - - wapp_str8_array_append_capped(output, item); - -RETURN_STR8_ARRAY_APPEND_ALLOC: - return output; -} - -Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other) { - Str8Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_STR8_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_str8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_STR8_ARRAY_EXTEND_ALLOC; - } - wapp_str8_array_copy_capped(array, output); - } - - wapp_str8_array_extend_capped(output, other); - -RETURN_STR8_ARRAY_EXTEND_ALLOC: - return output; -} - -Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst) { - Str8Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_STR8_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_str8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_STR8_ARRAY_COPY_ALLOC; - } - } - - wapp_str8_array_clear(output); - wapp_str8_array_copy_capped(src, output); - -RETURN_STR8_ARRAY_COPY_ALLOC: - return output; -} - -void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - void * *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_void_ptr_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_void_ptr_array_append_capped(array, *item); - } -} - -void wapp_void_ptr_array_clear(VoidPArray *array) { - if (!array) { - return; - } - - array->count = 0; -} - -void * wapp_void_ptr_array_pop(VoidPArray *array) { - if (!array || array->count == 0) { - return (void *){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst) { - if (!src || !dst) { - return; - } - - wapp_void_ptr_array_clear(dst); - - void * *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_void_ptr_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_void_ptr_array_append_capped(dst, *item); - } -} - -VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(VoidPArray) + sizeof(void *) * capacity; - VoidPArray *array = NULL; - - if (!allocator) { - goto RETURN_VOID_PTR_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_VOID_PTR_ARRAY_ALLOC; - } - - array->items = (void * *)((u8 *)array + sizeof(VoidPArray)); - array->count = 0; - array->capacity = capacity; - -RETURN_VOID_PTR_ARRAY_ALLOC: - return array; -} - -VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item) { - VoidPArray *output = array; - - if (!allocator || !array) { - goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; - } - wapp_void_ptr_array_copy_capped(array, output); - } - - wapp_void_ptr_array_append_capped(output, item); - -RETURN_VOID_PTR_ARRAY_APPEND_ALLOC: - return output; -} - -VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other) { - VoidPArray *output = array; - - if (!allocator || !array || !other) { - goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; - } - wapp_void_ptr_array_copy_capped(array, output); - } - - wapp_void_ptr_array_extend_capped(output, other); - -RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC: - return output; -} - -VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst) { - VoidPArray *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; - } - } - - wapp_void_ptr_array_clear(output); - wapp_void_ptr_array_copy_capped(src, output); - -RETURN_VOID_PTR_ARRAY_COPY_ALLOC: - return output; -} - -bool *wapp_bool_array_get(const BoolArray *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_bool_array_set(BoolArray *array, u64 index, bool item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_bool_array_append_capped(BoolArray *array, bool item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - bool *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_bool_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_bool_array_append_capped(array, *item); - } -} - -void wapp_bool_array_clear(BoolArray *array) { - if (!array) { - return; - } - - array->count = 0; -} - -bool wapp_bool_array_pop(BoolArray *array) { - if (!array || array->count == 0) { - return (bool){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst) { - if (!src || !dst) { - return; - } - - wapp_bool_array_clear(dst); - - bool *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_bool_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_bool_array_append_capped(dst, *item); - } -} - -BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(BoolArray) + sizeof(bool) * capacity; - BoolArray *array = NULL; - - if (!allocator) { - goto RETURN_BOOL_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_BOOL_ARRAY_ALLOC; - } - - array->items = (bool *)((u8 *)array + sizeof(BoolArray)); - array->count = 0; - array->capacity = capacity; - -RETURN_BOOL_ARRAY_ALLOC: - return array; -} - -BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item) { - BoolArray *output = array; - - if (!allocator || !array) { - goto RETURN_BOOL_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_bool_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_BOOL_ARRAY_APPEND_ALLOC; - } - wapp_bool_array_copy_capped(array, output); - } - - wapp_bool_array_append_capped(output, item); - -RETURN_BOOL_ARRAY_APPEND_ALLOC: - return output; -} - -BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other) { - BoolArray *output = array; - - if (!allocator || !array || !other) { - goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_bool_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; - } - wapp_bool_array_copy_capped(array, output); - } - - wapp_bool_array_extend_capped(output, other); - -RETURN_BOOL_ARRAY_EXTEND_ALLOC: - return output; -} - -BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst) { - BoolArray *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_BOOL_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_bool_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_BOOL_ARRAY_COPY_ALLOC; - } - } - - wapp_bool_array_clear(output); - wapp_bool_array_copy_capped(src, output); - -RETURN_BOOL_ARRAY_COPY_ALLOC: - return output; -} - -char *wapp_char_array_get(const CharArray *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_char_array_set(CharArray *array, u64 index, char item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_char_array_append_capped(CharArray *array, char item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_char_array_extend_capped(CharArray *array, const CharArray *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - char *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_char_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_char_array_append_capped(array, *item); - } -} - -void wapp_char_array_clear(CharArray *array) { - if (!array) { - return; - } - - array->count = 0; -} - -char wapp_char_array_pop(CharArray *array) { - if (!array || array->count == 0) { - return (char){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst) { - if (!src || !dst) { - return; - } - - wapp_char_array_clear(dst); - - char *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_char_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_char_array_append_capped(dst, *item); - } -} - -CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(CharArray) + sizeof(char) * capacity; - CharArray *array = NULL; - - if (!allocator) { - goto RETURN_CHAR_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_CHAR_ARRAY_ALLOC; - } - - array->items = (char *)((u8 *)array + sizeof(CharArray)); - array->count = 0; - array->capacity = capacity; - -RETURN_CHAR_ARRAY_ALLOC: - return array; -} - -CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item) { - CharArray *output = array; - - if (!allocator || !array) { - goto RETURN_CHAR_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_char_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_CHAR_ARRAY_APPEND_ALLOC; - } - wapp_char_array_copy_capped(array, output); - } - - wapp_char_array_append_capped(output, item); - -RETURN_CHAR_ARRAY_APPEND_ALLOC: - return output; -} - -CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other) { - CharArray *output = array; - - if (!allocator || !array || !other) { - goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_char_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; - } - wapp_char_array_copy_capped(array, output); - } - - wapp_char_array_extend_capped(output, other); - -RETURN_CHAR_ARRAY_EXTEND_ALLOC: - return output; -} - -CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst) { - CharArray *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_CHAR_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_char_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_CHAR_ARRAY_COPY_ALLOC; - } - } - - wapp_char_array_clear(output); - wapp_char_array_copy_capped(src, output); - -RETURN_CHAR_ARRAY_COPY_ALLOC: - return output; -} - -c8 *wapp_c8_array_get(const C8Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_c8_array_set(C8Array *array, u64 index, c8 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_c8_array_append_capped(C8Array *array, c8 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - c8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c8_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_c8_array_append_capped(array, *item); - } -} - -void wapp_c8_array_clear(C8Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -c8 wapp_c8_array_pop(C8Array *array) { - if (!array || array->count == 0) { - return (c8){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst) { - if (!src || !dst) { - return; - } - - wapp_c8_array_clear(dst); - - c8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c8_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_c8_array_append_capped(dst, *item); - } -} - -C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(C8Array) + sizeof(c8) * capacity; - C8Array *array = NULL; - - if (!allocator) { - goto RETURN_C8_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_C8_ARRAY_ALLOC; - } - - array->items = (c8 *)((u8 *)array + sizeof(C8Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_C8_ARRAY_ALLOC: - return array; -} - -C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item) { - C8Array *output = array; - - if (!allocator || !array) { - goto RETURN_C8_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C8_ARRAY_APPEND_ALLOC; - } - wapp_c8_array_copy_capped(array, output); - } - - wapp_c8_array_append_capped(output, item); - -RETURN_C8_ARRAY_APPEND_ALLOC: - return output; -} - -C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other) { - C8Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_C8_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C8_ARRAY_EXTEND_ALLOC; - } - wapp_c8_array_copy_capped(array, output); - } - - wapp_c8_array_extend_capped(output, other); - -RETURN_C8_ARRAY_EXTEND_ALLOC: - return output; -} - -C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst) { - C8Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_C8_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_c8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_C8_ARRAY_COPY_ALLOC; - } - } - - wapp_c8_array_clear(output); - wapp_c8_array_copy_capped(src, output); - -RETURN_C8_ARRAY_COPY_ALLOC: - return output; -} - -c16 *wapp_c16_array_get(const C16Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_c16_array_set(C16Array *array, u64 index, c16 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_c16_array_append_capped(C16Array *array, c16 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - c16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c16_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_c16_array_append_capped(array, *item); - } -} - -void wapp_c16_array_clear(C16Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -c16 wapp_c16_array_pop(C16Array *array) { - if (!array || array->count == 0) { - return (c16){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst) { - if (!src || !dst) { - return; - } - - wapp_c16_array_clear(dst); - - c16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c16_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_c16_array_append_capped(dst, *item); - } -} - -C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(C16Array) + sizeof(c16) * capacity; - C16Array *array = NULL; - - if (!allocator) { - goto RETURN_C16_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_C16_ARRAY_ALLOC; - } - - array->items = (c16 *)((u8 *)array + sizeof(C16Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_C16_ARRAY_ALLOC: - return array; -} - -C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item) { - C16Array *output = array; - - if (!allocator || !array) { - goto RETURN_C16_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C16_ARRAY_APPEND_ALLOC; - } - wapp_c16_array_copy_capped(array, output); - } - - wapp_c16_array_append_capped(output, item); - -RETURN_C16_ARRAY_APPEND_ALLOC: - return output; -} - -C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other) { - C16Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_C16_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C16_ARRAY_EXTEND_ALLOC; - } - wapp_c16_array_copy_capped(array, output); - } - - wapp_c16_array_extend_capped(output, other); - -RETURN_C16_ARRAY_EXTEND_ALLOC: - return output; -} - -C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst) { - C16Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_C16_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_c16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_C16_ARRAY_COPY_ALLOC; - } - } - - wapp_c16_array_clear(output); - wapp_c16_array_copy_capped(src, output); - -RETURN_C16_ARRAY_COPY_ALLOC: - return output; -} - -c32 *wapp_c32_array_get(const C32Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_c32_array_set(C32Array *array, u64 index, c32 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_c32_array_append_capped(C32Array *array, c32 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - c32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c32_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_c32_array_append_capped(array, *item); - } -} - -void wapp_c32_array_clear(C32Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -c32 wapp_c32_array_pop(C32Array *array) { - if (!array || array->count == 0) { - return (c32){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst) { - if (!src || !dst) { - return; - } - - wapp_c32_array_clear(dst); - - c32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_c32_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_c32_array_append_capped(dst, *item); - } -} - -C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(C32Array) + sizeof(c32) * capacity; - C32Array *array = NULL; - - if (!allocator) { - goto RETURN_C32_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_C32_ARRAY_ALLOC; - } - - array->items = (c32 *)((u8 *)array + sizeof(C32Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_C32_ARRAY_ALLOC: - return array; -} - -C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item) { - C32Array *output = array; - - if (!allocator || !array) { - goto RETURN_C32_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C32_ARRAY_APPEND_ALLOC; - } - wapp_c32_array_copy_capped(array, output); - } - - wapp_c32_array_append_capped(output, item); - -RETURN_C32_ARRAY_APPEND_ALLOC: - return output; -} - -C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other) { - C32Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_C32_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_c32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_C32_ARRAY_EXTEND_ALLOC; - } - wapp_c32_array_copy_capped(array, output); - } - - wapp_c32_array_extend_capped(output, other); - -RETURN_C32_ARRAY_EXTEND_ALLOC: - return output; -} - -C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst) { - C32Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_C32_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_c32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_C32_ARRAY_COPY_ALLOC; - } - } - - wapp_c32_array_clear(output); - wapp_c32_array_copy_capped(src, output); - -RETURN_C32_ARRAY_COPY_ALLOC: - return output; -} - -i8 *wapp_i8_array_get(const I8Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_i8_array_set(I8Array *array, u64 index, i8 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_i8_array_append_capped(I8Array *array, i8 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - i8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i8_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_i8_array_append_capped(array, *item); - } -} - -void wapp_i8_array_clear(I8Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -i8 wapp_i8_array_pop(I8Array *array) { - if (!array || array->count == 0) { - return (i8){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst) { - if (!src || !dst) { - return; - } - - wapp_i8_array_clear(dst); - - i8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i8_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_i8_array_append_capped(dst, *item); - } -} - -I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(I8Array) + sizeof(i8) * capacity; - I8Array *array = NULL; - - if (!allocator) { - goto RETURN_I8_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_I8_ARRAY_ALLOC; - } - - array->items = (i8 *)((u8 *)array + sizeof(I8Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_I8_ARRAY_ALLOC: - return array; -} - -I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item) { - I8Array *output = array; - - if (!allocator || !array) { - goto RETURN_I8_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I8_ARRAY_APPEND_ALLOC; - } - wapp_i8_array_copy_capped(array, output); - } - - wapp_i8_array_append_capped(output, item); - -RETURN_I8_ARRAY_APPEND_ALLOC: - return output; -} - -I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other) { - I8Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_I8_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I8_ARRAY_EXTEND_ALLOC; - } - wapp_i8_array_copy_capped(array, output); - } - - wapp_i8_array_extend_capped(output, other); - -RETURN_I8_ARRAY_EXTEND_ALLOC: - return output; -} - -I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst) { - I8Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_I8_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_i8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_I8_ARRAY_COPY_ALLOC; - } - } - - wapp_i8_array_clear(output); - wapp_i8_array_copy_capped(src, output); - -RETURN_I8_ARRAY_COPY_ALLOC: - return output; -} - -i16 *wapp_i16_array_get(const I16Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_i16_array_set(I16Array *array, u64 index, i16 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_i16_array_append_capped(I16Array *array, i16 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - i16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i16_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_i16_array_append_capped(array, *item); - } -} - -void wapp_i16_array_clear(I16Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -i16 wapp_i16_array_pop(I16Array *array) { - if (!array || array->count == 0) { - return (i16){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst) { - if (!src || !dst) { - return; - } - - wapp_i16_array_clear(dst); - - i16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i16_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_i16_array_append_capped(dst, *item); - } -} - -I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(I16Array) + sizeof(i16) * capacity; - I16Array *array = NULL; - - if (!allocator) { - goto RETURN_I16_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_I16_ARRAY_ALLOC; - } - - array->items = (i16 *)((u8 *)array + sizeof(I16Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_I16_ARRAY_ALLOC: - return array; -} - -I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item) { - I16Array *output = array; - - if (!allocator || !array) { - goto RETURN_I16_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I16_ARRAY_APPEND_ALLOC; - } - wapp_i16_array_copy_capped(array, output); - } - - wapp_i16_array_append_capped(output, item); - -RETURN_I16_ARRAY_APPEND_ALLOC: - return output; -} - -I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other) { - I16Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_I16_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I16_ARRAY_EXTEND_ALLOC; - } - wapp_i16_array_copy_capped(array, output); - } - - wapp_i16_array_extend_capped(output, other); - -RETURN_I16_ARRAY_EXTEND_ALLOC: - return output; -} - -I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst) { - I16Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_I16_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_i16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_I16_ARRAY_COPY_ALLOC; - } - } - - wapp_i16_array_clear(output); - wapp_i16_array_copy_capped(src, output); - -RETURN_I16_ARRAY_COPY_ALLOC: - return output; -} - -i32 *wapp_i32_array_get(const I32Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_i32_array_set(I32Array *array, u64 index, i32 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_i32_array_append_capped(I32Array *array, i32 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - i32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i32_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_i32_array_append_capped(array, *item); - } -} - -void wapp_i32_array_clear(I32Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -i32 wapp_i32_array_pop(I32Array *array) { - if (!array || array->count == 0) { - return (i32){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst) { - if (!src || !dst) { - return; - } - - wapp_i32_array_clear(dst); - - i32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i32_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_i32_array_append_capped(dst, *item); - } -} - -I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(I32Array) + sizeof(i32) * capacity; - I32Array *array = NULL; - - if (!allocator) { - goto RETURN_I32_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_I32_ARRAY_ALLOC; - } - - array->items = (i32 *)((u8 *)array + sizeof(I32Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_I32_ARRAY_ALLOC: - return array; -} - -I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item) { - I32Array *output = array; - - if (!allocator || !array) { - goto RETURN_I32_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I32_ARRAY_APPEND_ALLOC; - } - wapp_i32_array_copy_capped(array, output); - } - - wapp_i32_array_append_capped(output, item); - -RETURN_I32_ARRAY_APPEND_ALLOC: - return output; -} - -I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other) { - I32Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_I32_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I32_ARRAY_EXTEND_ALLOC; - } - wapp_i32_array_copy_capped(array, output); - } - - wapp_i32_array_extend_capped(output, other); - -RETURN_I32_ARRAY_EXTEND_ALLOC: - return output; -} - -I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst) { - I32Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_I32_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_i32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_I32_ARRAY_COPY_ALLOC; - } - } - - wapp_i32_array_clear(output); - wapp_i32_array_copy_capped(src, output); - -RETURN_I32_ARRAY_COPY_ALLOC: - return output; -} - -i64 *wapp_i64_array_get(const I64Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_i64_array_set(I64Array *array, u64 index, i64 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_i64_array_append_capped(I64Array *array, i64 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - i64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i64_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_i64_array_append_capped(array, *item); - } -} - -void wapp_i64_array_clear(I64Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -i64 wapp_i64_array_pop(I64Array *array) { - if (!array || array->count == 0) { - return (i64){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst) { - if (!src || !dst) { - return; - } - - wapp_i64_array_clear(dst); - - i64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_i64_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_i64_array_append_capped(dst, *item); - } -} - -I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(I64Array) + sizeof(i64) * capacity; - I64Array *array = NULL; - - if (!allocator) { - goto RETURN_I64_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_I64_ARRAY_ALLOC; - } - - array->items = (i64 *)((u8 *)array + sizeof(I64Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_I64_ARRAY_ALLOC: - return array; -} - -I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item) { - I64Array *output = array; - - if (!allocator || !array) { - goto RETURN_I64_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I64_ARRAY_APPEND_ALLOC; - } - wapp_i64_array_copy_capped(array, output); - } - - wapp_i64_array_append_capped(output, item); - -RETURN_I64_ARRAY_APPEND_ALLOC: - return output; -} - -I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other) { - I64Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_I64_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_i64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_I64_ARRAY_EXTEND_ALLOC; - } - wapp_i64_array_copy_capped(array, output); - } - - wapp_i64_array_extend_capped(output, other); - -RETURN_I64_ARRAY_EXTEND_ALLOC: - return output; -} - -I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst) { - I64Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_I64_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_i64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_I64_ARRAY_COPY_ALLOC; - } - } - - wapp_i64_array_clear(output); - wapp_i64_array_copy_capped(src, output); - -RETURN_I64_ARRAY_COPY_ALLOC: - return output; -} - -u8 *wapp_u8_array_get(const U8Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_u8_array_set(U8Array *array, u64 index, u8 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_u8_array_append_capped(U8Array *array, u8 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - u8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u8_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_u8_array_append_capped(array, *item); - } -} - -void wapp_u8_array_clear(U8Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -u8 wapp_u8_array_pop(U8Array *array) { - if (!array || array->count == 0) { - return (u8){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst) { - if (!src || !dst) { - return; - } - - wapp_u8_array_clear(dst); - - u8 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u8_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_u8_array_append_capped(dst, *item); - } -} - -U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(U8Array) + sizeof(u8) * capacity; - U8Array *array = NULL; - - if (!allocator) { - goto RETURN_U8_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_U8_ARRAY_ALLOC; - } - - array->items = (u8 *)((u8 *)array + sizeof(U8Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_U8_ARRAY_ALLOC: - return array; -} - -U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item) { - U8Array *output = array; - - if (!allocator || !array) { - goto RETURN_U8_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U8_ARRAY_APPEND_ALLOC; - } - wapp_u8_array_copy_capped(array, output); - } - - wapp_u8_array_append_capped(output, item); - -RETURN_U8_ARRAY_APPEND_ALLOC: - return output; -} - -U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other) { - U8Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_U8_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U8_ARRAY_EXTEND_ALLOC; - } - wapp_u8_array_copy_capped(array, output); - } - - wapp_u8_array_extend_capped(output, other); - -RETURN_U8_ARRAY_EXTEND_ALLOC: - return output; -} - -U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst) { - U8Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_U8_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_u8_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_U8_ARRAY_COPY_ALLOC; - } - } - - wapp_u8_array_clear(output); - wapp_u8_array_copy_capped(src, output); - -RETURN_U8_ARRAY_COPY_ALLOC: - return output; -} - -u16 *wapp_u16_array_get(const U16Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_u16_array_set(U16Array *array, u64 index, u16 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_u16_array_append_capped(U16Array *array, u16 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - u16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u16_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_u16_array_append_capped(array, *item); - } -} - -void wapp_u16_array_clear(U16Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -u16 wapp_u16_array_pop(U16Array *array) { - if (!array || array->count == 0) { - return (u16){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst) { - if (!src || !dst) { - return; - } - - wapp_u16_array_clear(dst); - - u16 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u16_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_u16_array_append_capped(dst, *item); - } -} - -U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(U16Array) + sizeof(u16) * capacity; - U16Array *array = NULL; - - if (!allocator) { - goto RETURN_U16_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_U16_ARRAY_ALLOC; - } - - array->items = (u16 *)((u8 *)array + sizeof(U16Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_U16_ARRAY_ALLOC: - return array; -} - -U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item) { - U16Array *output = array; - - if (!allocator || !array) { - goto RETURN_U16_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U16_ARRAY_APPEND_ALLOC; - } - wapp_u16_array_copy_capped(array, output); - } - - wapp_u16_array_append_capped(output, item); - -RETURN_U16_ARRAY_APPEND_ALLOC: - return output; -} - -U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other) { - U16Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_U16_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U16_ARRAY_EXTEND_ALLOC; - } - wapp_u16_array_copy_capped(array, output); - } - - wapp_u16_array_extend_capped(output, other); - -RETURN_U16_ARRAY_EXTEND_ALLOC: - return output; -} - -U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst) { - U16Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_U16_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_u16_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_U16_ARRAY_COPY_ALLOC; - } - } - - wapp_u16_array_clear(output); - wapp_u16_array_copy_capped(src, output); - -RETURN_U16_ARRAY_COPY_ALLOC: - return output; -} - -u32 *wapp_u32_array_get(const U32Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_u32_array_set(U32Array *array, u64 index, u32 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_u32_array_append_capped(U32Array *array, u32 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - u32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u32_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_u32_array_append_capped(array, *item); - } -} - -void wapp_u32_array_clear(U32Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -u32 wapp_u32_array_pop(U32Array *array) { - if (!array || array->count == 0) { - return (u32){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst) { - if (!src || !dst) { - return; - } - - wapp_u32_array_clear(dst); - - u32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u32_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_u32_array_append_capped(dst, *item); - } -} - -U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(U32Array) + sizeof(u32) * capacity; - U32Array *array = NULL; - - if (!allocator) { - goto RETURN_U32_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_U32_ARRAY_ALLOC; - } - - array->items = (u32 *)((u8 *)array + sizeof(U32Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_U32_ARRAY_ALLOC: - return array; -} - -U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item) { - U32Array *output = array; - - if (!allocator || !array) { - goto RETURN_U32_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U32_ARRAY_APPEND_ALLOC; - } - wapp_u32_array_copy_capped(array, output); - } - - wapp_u32_array_append_capped(output, item); - -RETURN_U32_ARRAY_APPEND_ALLOC: - return output; -} - -U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other) { - U32Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_U32_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U32_ARRAY_EXTEND_ALLOC; - } - wapp_u32_array_copy_capped(array, output); - } - - wapp_u32_array_extend_capped(output, other); - -RETURN_U32_ARRAY_EXTEND_ALLOC: - return output; -} - -U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst) { - U32Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_U32_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_u32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_U32_ARRAY_COPY_ALLOC; - } - } - - wapp_u32_array_clear(output); - wapp_u32_array_copy_capped(src, output); - -RETURN_U32_ARRAY_COPY_ALLOC: - return output; -} - -u64 *wapp_u64_array_get(const U64Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_u64_array_set(U64Array *array, u64 index, u64 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_u64_array_append_capped(U64Array *array, u64 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - u64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u64_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_u64_array_append_capped(array, *item); - } -} - -void wapp_u64_array_clear(U64Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -u64 wapp_u64_array_pop(U64Array *array) { - if (!array || array->count == 0) { - return (u64){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst) { - if (!src || !dst) { - return; - } - - wapp_u64_array_clear(dst); - - u64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_u64_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_u64_array_append_capped(dst, *item); - } -} - -U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(U64Array) + sizeof(u64) * capacity; - U64Array *array = NULL; - - if (!allocator) { - goto RETURN_U64_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_U64_ARRAY_ALLOC; - } - - array->items = (u64 *)((u8 *)array + sizeof(U64Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_U64_ARRAY_ALLOC: - return array; -} - -U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item) { - U64Array *output = array; - - if (!allocator || !array) { - goto RETURN_U64_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U64_ARRAY_APPEND_ALLOC; - } - wapp_u64_array_copy_capped(array, output); - } - - wapp_u64_array_append_capped(output, item); - -RETURN_U64_ARRAY_APPEND_ALLOC: - return output; -} - -U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other) { - U64Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_U64_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_u64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_U64_ARRAY_EXTEND_ALLOC; - } - wapp_u64_array_copy_capped(array, output); - } - - wapp_u64_array_extend_capped(output, other); - -RETURN_U64_ARRAY_EXTEND_ALLOC: - return output; -} - -U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst) { - U64Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_U64_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_u64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_U64_ARRAY_COPY_ALLOC; - } - } - - wapp_u64_array_clear(output); - wapp_u64_array_copy_capped(src, output); - -RETURN_U64_ARRAY_COPY_ALLOC: - return output; -} - -f32 *wapp_f32_array_get(const F32Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_f32_array_set(F32Array *array, u64 index, f32 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_f32_array_append_capped(F32Array *array, f32 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - f32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f32_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_f32_array_append_capped(array, *item); - } -} - -void wapp_f32_array_clear(F32Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -f32 wapp_f32_array_pop(F32Array *array) { - if (!array || array->count == 0) { - return (f32){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst) { - if (!src || !dst) { - return; - } - - wapp_f32_array_clear(dst); - - f32 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f32_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_f32_array_append_capped(dst, *item); - } -} - -F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(F32Array) + sizeof(f32) * capacity; - F32Array *array = NULL; - - if (!allocator) { - goto RETURN_F32_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_F32_ARRAY_ALLOC; - } - - array->items = (f32 *)((u8 *)array + sizeof(F32Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_F32_ARRAY_ALLOC: - return array; -} - -F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item) { - F32Array *output = array; - - if (!allocator || !array) { - goto RETURN_F32_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F32_ARRAY_APPEND_ALLOC; - } - wapp_f32_array_copy_capped(array, output); - } - - wapp_f32_array_append_capped(output, item); - -RETURN_F32_ARRAY_APPEND_ALLOC: - return output; -} - -F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other) { - F32Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_F32_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F32_ARRAY_EXTEND_ALLOC; - } - wapp_f32_array_copy_capped(array, output); - } - - wapp_f32_array_extend_capped(output, other); - -RETURN_F32_ARRAY_EXTEND_ALLOC: - return output; -} - -F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst) { - F32Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_F32_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_f32_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_F32_ARRAY_COPY_ALLOC; - } - } - - wapp_f32_array_clear(output); - wapp_f32_array_copy_capped(src, output); - -RETURN_F32_ARRAY_COPY_ALLOC: - return output; -} - -f64 *wapp_f64_array_get(const F64Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_f64_array_set(F64Array *array, u64 index, f64 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_f64_array_append_capped(F64Array *array, f64 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - f64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f64_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_f64_array_append_capped(array, *item); - } -} - -void wapp_f64_array_clear(F64Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -f64 wapp_f64_array_pop(F64Array *array) { - if (!array || array->count == 0) { - return (f64){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst) { - if (!src || !dst) { - return; - } - - wapp_f64_array_clear(dst); - - f64 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f64_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_f64_array_append_capped(dst, *item); - } -} - -F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(F64Array) + sizeof(f64) * capacity; - F64Array *array = NULL; - - if (!allocator) { - goto RETURN_F64_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_F64_ARRAY_ALLOC; - } - - array->items = (f64 *)((u8 *)array + sizeof(F64Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_F64_ARRAY_ALLOC: - return array; -} - -F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item) { - F64Array *output = array; - - if (!allocator || !array) { - goto RETURN_F64_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F64_ARRAY_APPEND_ALLOC; - } - wapp_f64_array_copy_capped(array, output); - } - - wapp_f64_array_append_capped(output, item); - -RETURN_F64_ARRAY_APPEND_ALLOC: - return output; -} - -F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other) { - F64Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_F64_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F64_ARRAY_EXTEND_ALLOC; - } - wapp_f64_array_copy_capped(array, output); - } - - wapp_f64_array_extend_capped(output, other); - -RETURN_F64_ARRAY_EXTEND_ALLOC: - return output; -} - -F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst) { - F64Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_F64_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_f64_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_F64_ARRAY_COPY_ALLOC; - } - } - - wapp_f64_array_clear(output); - wapp_f64_array_copy_capped(src, output); - -RETURN_F64_ARRAY_COPY_ALLOC: - return output; -} - -f128 *wapp_f128_array_get(const F128Array *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_f128_array_set(F128Array *array, u64 index, f128 item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_f128_array_append_capped(F128Array *array, f128 item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - f128 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f128_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_f128_array_append_capped(array, *item); - } -} - -void wapp_f128_array_clear(F128Array *array) { - if (!array) { - return; - } - - array->count = 0; -} - -f128 wapp_f128_array_pop(F128Array *array) { - if (!array || array->count == 0) { - return (f128){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst) { - if (!src || !dst) { - return; - } - - wapp_f128_array_clear(dst); - - f128 *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_f128_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_f128_array_append_capped(dst, *item); - } -} - -F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(F128Array) + sizeof(f128) * capacity; - F128Array *array = NULL; - - if (!allocator) { - goto RETURN_F128_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_F128_ARRAY_ALLOC; - } - - array->items = (f128 *)((u8 *)array + sizeof(F128Array)); - array->count = 0; - array->capacity = capacity; - -RETURN_F128_ARRAY_ALLOC: - return array; -} - -F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item) { - F128Array *output = array; - - if (!allocator || !array) { - goto RETURN_F128_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f128_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F128_ARRAY_APPEND_ALLOC; - } - wapp_f128_array_copy_capped(array, output); - } - - wapp_f128_array_append_capped(output, item); - -RETURN_F128_ARRAY_APPEND_ALLOC: - return output; -} - -F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other) { - F128Array *output = array; - - if (!allocator || !array || !other) { - goto RETURN_F128_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_f128_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_F128_ARRAY_EXTEND_ALLOC; - } - wapp_f128_array_copy_capped(array, output); - } - - wapp_f128_array_extend_capped(output, other); - -RETURN_F128_ARRAY_EXTEND_ALLOC: - return output; -} - -F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst) { - F128Array *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_F128_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_f128_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_F128_ARRAY_COPY_ALLOC; - } - } - - wapp_f128_array_clear(output); - wapp_f128_array_copy_capped(src, output); - -RETURN_F128_ARRAY_COPY_ALLOC: - return output; -} - -iptr *wapp_iptr_array_get(const IptrArray *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_iptr_array_append_capped(IptrArray *array, iptr item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - iptr *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_iptr_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_iptr_array_append_capped(array, *item); - } -} - -void wapp_iptr_array_clear(IptrArray *array) { - if (!array) { - return; - } - - array->count = 0; -} - -iptr wapp_iptr_array_pop(IptrArray *array) { - if (!array || array->count == 0) { - return (iptr){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst) { - if (!src || !dst) { - return; - } - - wapp_iptr_array_clear(dst); - - iptr *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_iptr_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_iptr_array_append_capped(dst, *item); - } -} - -IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(IptrArray) + sizeof(iptr) * capacity; - IptrArray *array = NULL; - - if (!allocator) { - goto RETURN_IPTR_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_IPTR_ARRAY_ALLOC; - } - - array->items = (iptr *)((u8 *)array + sizeof(IptrArray)); - array->count = 0; - array->capacity = capacity; - -RETURN_IPTR_ARRAY_ALLOC: - return array; -} - -IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item) { - IptrArray *output = array; - - if (!allocator || !array) { - goto RETURN_IPTR_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_IPTR_ARRAY_APPEND_ALLOC; - } - wapp_iptr_array_copy_capped(array, output); - } - - wapp_iptr_array_append_capped(output, item); - -RETURN_IPTR_ARRAY_APPEND_ALLOC: - return output; -} - -IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other) { - IptrArray *output = array; - - if (!allocator || !array || !other) { - goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; - } - wapp_iptr_array_copy_capped(array, output); - } - - wapp_iptr_array_extend_capped(output, other); - -RETURN_IPTR_ARRAY_EXTEND_ALLOC: - return output; -} - -IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst) { - IptrArray *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_IPTR_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_IPTR_ARRAY_COPY_ALLOC; - } - } - - wapp_iptr_array_clear(output); - wapp_iptr_array_copy_capped(src, output); - -RETURN_IPTR_ARRAY_COPY_ALLOC: - return output; -} - -uptr *wapp_uptr_array_get(const UptrArray *array, u64 index) { - if (!array || index >= array->count) { - return NULL; - } - - return &(array->items[index]); -} - -void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item) { - if (!array || index >= array->count) { - return; - } - - array->items[index] = item; -} - -void wapp_uptr_array_append_capped(UptrArray *array, uptr item) { - if (!array || array->count >= array->capacity) { - return; - } - - array->items[(array->count)++] = item; -} - -void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other) { - if (!array || !other) { - return; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - return; - } - - uptr *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 items_to_add = other->count; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_uptr_array_get(other, item_index); - ++item_index; - running = item_index < items_to_add; - - if (!item) { - continue; - } - - wapp_uptr_array_append_capped(array, *item); - } -} - -void wapp_uptr_array_clear(UptrArray *array) { - if (!array) { - return; - } - - array->count = 0; -} - -uptr wapp_uptr_array_pop(UptrArray *array) { - if (!array || array->count == 0) { - return (uptr){0}; - } - - return array->items[--(array->count)]; -} - -void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst) { - if (!src || !dst) { - return; - } - - wapp_uptr_array_clear(dst); - - uptr *item; - - // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of - // MSVC Spectre mitigation warnings - u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; - u64 item_index = 0; - bool running = true; - while (running) { - item = wapp_uptr_array_get(src, item_index); - ++item_index; - running = item_index < to_copy; - - if (!item) { - continue; - } - - wapp_uptr_array_append_capped(dst, *item); - } -} - -UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { - u64 allocation_size = sizeof(UptrArray) + sizeof(uptr) * capacity; - UptrArray *array = NULL; - - if (!allocator) { - goto RETURN_UPTR_ARRAY_ALLOC; - } - - array = wapp_mem_allocator_alloc(allocator, allocation_size); - if (!array) { - goto RETURN_UPTR_ARRAY_ALLOC; - } - - array->items = (uptr *)((u8 *)array + sizeof(UptrArray)); - array->count = 0; - array->capacity = capacity; - -RETURN_UPTR_ARRAY_ALLOC: - return array; -} - -UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item) { - UptrArray *output = array; - - if (!allocator || !array) { - goto RETURN_UPTR_ARRAY_APPEND_ALLOC; - } - - if (array->count >= array->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_UPTR_ARRAY_APPEND_ALLOC; - } - wapp_uptr_array_copy_capped(array, output); - } - - wapp_uptr_array_append_capped(output, item); - -RETURN_UPTR_ARRAY_APPEND_ALLOC: - return output; -} - -UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other) { - UptrArray *output = array; - - if (!allocator || !array || !other) { - goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; - } - - u64 remaining_capacity = array->capacity - array->count; - if (other->count >= remaining_capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); - output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = array; - goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; - } - wapp_uptr_array_copy_capped(array, output); - } - - wapp_uptr_array_extend_capped(output, other); - -RETURN_UPTR_ARRAY_EXTEND_ALLOC: - return output; -} - -UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst) { - UptrArray *output = dst; - - if (!allocator || !src || !dst) { - goto RETURN_UPTR_ARRAY_COPY_ALLOC; - } - - if (src->count >= dst->capacity) { - u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); - output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); - if (!output) { - output = dst; - goto RETURN_UPTR_ARRAY_COPY_ALLOC; - } - } - - wapp_uptr_array_clear(output); - wapp_uptr_array_copy_capped(src, output); - -RETURN_UPTR_ARRAY_COPY_ALLOC: - return output; -} - +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#include "./array.h" +#include "../mem_allocator/mem_allocator.h" +#include "../strings/str8/str8.h" +#include "../../common/misc/misc_utils.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include +#include + +Str8 *wapp_str8_array_get(const Str8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_str8_array_append_capped(Str8Array *array, Str8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + Str8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_str8_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_str8_array_append_capped(array, *item); + } +} + +void wapp_str8_array_clear(Str8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +Str8 wapp_str8_array_pop(Str8Array *array) { + if (!array || array->count == 0) { + return (Str8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_str8_array_clear(dst); + + Str8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_str8_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_str8_array_append_capped(dst, *item); + } +} + +Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(Str8Array) + sizeof(Str8) * capacity; + Str8Array *array = NULL; + + if (!allocator) { + goto RETURN_STR8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_STR8_ARRAY_ALLOC; + } + + array->items = (Str8 *)((u8 *)array + sizeof(Str8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_STR8_ARRAY_ALLOC: + return array; +} + +Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item) { + Str8Array *output = array; + + if (!allocator || !array) { + goto RETURN_STR8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_STR8_ARRAY_APPEND_ALLOC; + } + wapp_str8_array_copy_capped(array, output); + } + + wapp_str8_array_append_capped(output, item); + +RETURN_STR8_ARRAY_APPEND_ALLOC: + return output; +} + +Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other) { + Str8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_STR8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_STR8_ARRAY_EXTEND_ALLOC; + } + wapp_str8_array_copy_capped(array, output); + } + + wapp_str8_array_extend_capped(output, other); + +RETURN_STR8_ARRAY_EXTEND_ALLOC: + return output; +} + +Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst) { + Str8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_STR8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_STR8_ARRAY_COPY_ALLOC; + } + } + + wapp_str8_array_clear(output); + wapp_str8_array_copy_capped(src, output); + +RETURN_STR8_ARRAY_COPY_ALLOC: + return output; +} + +void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + void * *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_void_ptr_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_void_ptr_array_append_capped(array, *item); + } +} + +void wapp_void_ptr_array_clear(VoidPArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +void * wapp_void_ptr_array_pop(VoidPArray *array) { + if (!array || array->count == 0) { + return (void *){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst) { + if (!src || !dst) { + return; + } + + wapp_void_ptr_array_clear(dst); + + void * *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_void_ptr_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_void_ptr_array_append_capped(dst, *item); + } +} + +VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(VoidPArray) + sizeof(void *) * capacity; + VoidPArray *array = NULL; + + if (!allocator) { + goto RETURN_VOID_PTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_VOID_PTR_ARRAY_ALLOC; + } + + array->items = (void * *)((u8 *)array + sizeof(VoidPArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_VOID_PTR_ARRAY_ALLOC: + return array; +} + +VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item) { + VoidPArray *output = array; + + if (!allocator || !array) { + goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; + } + wapp_void_ptr_array_copy_capped(array, output); + } + + wapp_void_ptr_array_append_capped(output, item); + +RETURN_VOID_PTR_ARRAY_APPEND_ALLOC: + return output; +} + +VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other) { + VoidPArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; + } + wapp_void_ptr_array_copy_capped(array, output); + } + + wapp_void_ptr_array_extend_capped(output, other); + +RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC: + return output; +} + +VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst) { + VoidPArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; + } + } + + wapp_void_ptr_array_clear(output); + wapp_void_ptr_array_copy_capped(src, output); + +RETURN_VOID_PTR_ARRAY_COPY_ALLOC: + return output; +} + +bool *wapp_bool_array_get(const BoolArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_bool_array_set(BoolArray *array, u64 index, bool item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_bool_array_append_capped(BoolArray *array, bool item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + bool *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_bool_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_bool_array_append_capped(array, *item); + } +} + +void wapp_bool_array_clear(BoolArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +bool wapp_bool_array_pop(BoolArray *array) { + if (!array || array->count == 0) { + return (bool){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst) { + if (!src || !dst) { + return; + } + + wapp_bool_array_clear(dst); + + bool *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_bool_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_bool_array_append_capped(dst, *item); + } +} + +BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(BoolArray) + sizeof(bool) * capacity; + BoolArray *array = NULL; + + if (!allocator) { + goto RETURN_BOOL_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_BOOL_ARRAY_ALLOC; + } + + array->items = (bool *)((u8 *)array + sizeof(BoolArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_BOOL_ARRAY_ALLOC: + return array; +} + +BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item) { + BoolArray *output = array; + + if (!allocator || !array) { + goto RETURN_BOOL_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_BOOL_ARRAY_APPEND_ALLOC; + } + wapp_bool_array_copy_capped(array, output); + } + + wapp_bool_array_append_capped(output, item); + +RETURN_BOOL_ARRAY_APPEND_ALLOC: + return output; +} + +BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other) { + BoolArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; + } + wapp_bool_array_copy_capped(array, output); + } + + wapp_bool_array_extend_capped(output, other); + +RETURN_BOOL_ARRAY_EXTEND_ALLOC: + return output; +} + +BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst) { + BoolArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_BOOL_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_BOOL_ARRAY_COPY_ALLOC; + } + } + + wapp_bool_array_clear(output); + wapp_bool_array_copy_capped(src, output); + +RETURN_BOOL_ARRAY_COPY_ALLOC: + return output; +} + +char *wapp_char_array_get(const CharArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_char_array_set(CharArray *array, u64 index, char item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_char_array_append_capped(CharArray *array, char item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_char_array_extend_capped(CharArray *array, const CharArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + char *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_char_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_char_array_append_capped(array, *item); + } +} + +void wapp_char_array_clear(CharArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +char wapp_char_array_pop(CharArray *array) { + if (!array || array->count == 0) { + return (char){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst) { + if (!src || !dst) { + return; + } + + wapp_char_array_clear(dst); + + char *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_char_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_char_array_append_capped(dst, *item); + } +} + +CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(CharArray) + sizeof(char) * capacity; + CharArray *array = NULL; + + if (!allocator) { + goto RETURN_CHAR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_CHAR_ARRAY_ALLOC; + } + + array->items = (char *)((u8 *)array + sizeof(CharArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_CHAR_ARRAY_ALLOC: + return array; +} + +CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item) { + CharArray *output = array; + + if (!allocator || !array) { + goto RETURN_CHAR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_CHAR_ARRAY_APPEND_ALLOC; + } + wapp_char_array_copy_capped(array, output); + } + + wapp_char_array_append_capped(output, item); + +RETURN_CHAR_ARRAY_APPEND_ALLOC: + return output; +} + +CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other) { + CharArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; + } + wapp_char_array_copy_capped(array, output); + } + + wapp_char_array_extend_capped(output, other); + +RETURN_CHAR_ARRAY_EXTEND_ALLOC: + return output; +} + +CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst) { + CharArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_CHAR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_CHAR_ARRAY_COPY_ALLOC; + } + } + + wapp_char_array_clear(output); + wapp_char_array_copy_capped(src, output); + +RETURN_CHAR_ARRAY_COPY_ALLOC: + return output; +} + +c8 *wapp_c8_array_get(const C8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c8_array_set(C8Array *array, u64 index, c8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c8_array_append_capped(C8Array *array, c8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c8_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_c8_array_append_capped(array, *item); + } +} + +void wapp_c8_array_clear(C8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c8 wapp_c8_array_pop(C8Array *array) { + if (!array || array->count == 0) { + return (c8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c8_array_clear(dst); + + c8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c8_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_c8_array_append_capped(dst, *item); + } +} + +C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C8Array) + sizeof(c8) * capacity; + C8Array *array = NULL; + + if (!allocator) { + goto RETURN_C8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C8_ARRAY_ALLOC; + } + + array->items = (c8 *)((u8 *)array + sizeof(C8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C8_ARRAY_ALLOC: + return array; +} + +C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item) { + C8Array *output = array; + + if (!allocator || !array) { + goto RETURN_C8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C8_ARRAY_APPEND_ALLOC; + } + wapp_c8_array_copy_capped(array, output); + } + + wapp_c8_array_append_capped(output, item); + +RETURN_C8_ARRAY_APPEND_ALLOC: + return output; +} + +C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other) { + C8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C8_ARRAY_EXTEND_ALLOC; + } + wapp_c8_array_copy_capped(array, output); + } + + wapp_c8_array_extend_capped(output, other); + +RETURN_C8_ARRAY_EXTEND_ALLOC: + return output; +} + +C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst) { + C8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C8_ARRAY_COPY_ALLOC; + } + } + + wapp_c8_array_clear(output); + wapp_c8_array_copy_capped(src, output); + +RETURN_C8_ARRAY_COPY_ALLOC: + return output; +} + +c16 *wapp_c16_array_get(const C16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c16_array_set(C16Array *array, u64 index, c16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c16_array_append_capped(C16Array *array, c16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c16_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_c16_array_append_capped(array, *item); + } +} + +void wapp_c16_array_clear(C16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c16 wapp_c16_array_pop(C16Array *array) { + if (!array || array->count == 0) { + return (c16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c16_array_clear(dst); + + c16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c16_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_c16_array_append_capped(dst, *item); + } +} + +C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C16Array) + sizeof(c16) * capacity; + C16Array *array = NULL; + + if (!allocator) { + goto RETURN_C16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C16_ARRAY_ALLOC; + } + + array->items = (c16 *)((u8 *)array + sizeof(C16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C16_ARRAY_ALLOC: + return array; +} + +C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item) { + C16Array *output = array; + + if (!allocator || !array) { + goto RETURN_C16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C16_ARRAY_APPEND_ALLOC; + } + wapp_c16_array_copy_capped(array, output); + } + + wapp_c16_array_append_capped(output, item); + +RETURN_C16_ARRAY_APPEND_ALLOC: + return output; +} + +C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other) { + C16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C16_ARRAY_EXTEND_ALLOC; + } + wapp_c16_array_copy_capped(array, output); + } + + wapp_c16_array_extend_capped(output, other); + +RETURN_C16_ARRAY_EXTEND_ALLOC: + return output; +} + +C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst) { + C16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C16_ARRAY_COPY_ALLOC; + } + } + + wapp_c16_array_clear(output); + wapp_c16_array_copy_capped(src, output); + +RETURN_C16_ARRAY_COPY_ALLOC: + return output; +} + +c32 *wapp_c32_array_get(const C32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c32_array_set(C32Array *array, u64 index, c32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c32_array_append_capped(C32Array *array, c32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c32_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_c32_array_append_capped(array, *item); + } +} + +void wapp_c32_array_clear(C32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c32 wapp_c32_array_pop(C32Array *array) { + if (!array || array->count == 0) { + return (c32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c32_array_clear(dst); + + c32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_c32_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_c32_array_append_capped(dst, *item); + } +} + +C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C32Array) + sizeof(c32) * capacity; + C32Array *array = NULL; + + if (!allocator) { + goto RETURN_C32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C32_ARRAY_ALLOC; + } + + array->items = (c32 *)((u8 *)array + sizeof(C32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C32_ARRAY_ALLOC: + return array; +} + +C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item) { + C32Array *output = array; + + if (!allocator || !array) { + goto RETURN_C32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C32_ARRAY_APPEND_ALLOC; + } + wapp_c32_array_copy_capped(array, output); + } + + wapp_c32_array_append_capped(output, item); + +RETURN_C32_ARRAY_APPEND_ALLOC: + return output; +} + +C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other) { + C32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C32_ARRAY_EXTEND_ALLOC; + } + wapp_c32_array_copy_capped(array, output); + } + + wapp_c32_array_extend_capped(output, other); + +RETURN_C32_ARRAY_EXTEND_ALLOC: + return output; +} + +C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst) { + C32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C32_ARRAY_COPY_ALLOC; + } + } + + wapp_c32_array_clear(output); + wapp_c32_array_copy_capped(src, output); + +RETURN_C32_ARRAY_COPY_ALLOC: + return output; +} + +i8 *wapp_i8_array_get(const I8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i8_array_set(I8Array *array, u64 index, i8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i8_array_append_capped(I8Array *array, i8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i8_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_i8_array_append_capped(array, *item); + } +} + +void wapp_i8_array_clear(I8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i8 wapp_i8_array_pop(I8Array *array) { + if (!array || array->count == 0) { + return (i8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i8_array_clear(dst); + + i8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i8_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_i8_array_append_capped(dst, *item); + } +} + +I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I8Array) + sizeof(i8) * capacity; + I8Array *array = NULL; + + if (!allocator) { + goto RETURN_I8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I8_ARRAY_ALLOC; + } + + array->items = (i8 *)((u8 *)array + sizeof(I8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I8_ARRAY_ALLOC: + return array; +} + +I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item) { + I8Array *output = array; + + if (!allocator || !array) { + goto RETURN_I8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I8_ARRAY_APPEND_ALLOC; + } + wapp_i8_array_copy_capped(array, output); + } + + wapp_i8_array_append_capped(output, item); + +RETURN_I8_ARRAY_APPEND_ALLOC: + return output; +} + +I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other) { + I8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I8_ARRAY_EXTEND_ALLOC; + } + wapp_i8_array_copy_capped(array, output); + } + + wapp_i8_array_extend_capped(output, other); + +RETURN_I8_ARRAY_EXTEND_ALLOC: + return output; +} + +I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst) { + I8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I8_ARRAY_COPY_ALLOC; + } + } + + wapp_i8_array_clear(output); + wapp_i8_array_copy_capped(src, output); + +RETURN_I8_ARRAY_COPY_ALLOC: + return output; +} + +i16 *wapp_i16_array_get(const I16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i16_array_set(I16Array *array, u64 index, i16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i16_array_append_capped(I16Array *array, i16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i16_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_i16_array_append_capped(array, *item); + } +} + +void wapp_i16_array_clear(I16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i16 wapp_i16_array_pop(I16Array *array) { + if (!array || array->count == 0) { + return (i16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i16_array_clear(dst); + + i16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i16_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_i16_array_append_capped(dst, *item); + } +} + +I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I16Array) + sizeof(i16) * capacity; + I16Array *array = NULL; + + if (!allocator) { + goto RETURN_I16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I16_ARRAY_ALLOC; + } + + array->items = (i16 *)((u8 *)array + sizeof(I16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I16_ARRAY_ALLOC: + return array; +} + +I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item) { + I16Array *output = array; + + if (!allocator || !array) { + goto RETURN_I16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I16_ARRAY_APPEND_ALLOC; + } + wapp_i16_array_copy_capped(array, output); + } + + wapp_i16_array_append_capped(output, item); + +RETURN_I16_ARRAY_APPEND_ALLOC: + return output; +} + +I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other) { + I16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I16_ARRAY_EXTEND_ALLOC; + } + wapp_i16_array_copy_capped(array, output); + } + + wapp_i16_array_extend_capped(output, other); + +RETURN_I16_ARRAY_EXTEND_ALLOC: + return output; +} + +I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst) { + I16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I16_ARRAY_COPY_ALLOC; + } + } + + wapp_i16_array_clear(output); + wapp_i16_array_copy_capped(src, output); + +RETURN_I16_ARRAY_COPY_ALLOC: + return output; +} + +i32 *wapp_i32_array_get(const I32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i32_array_set(I32Array *array, u64 index, i32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i32_array_append_capped(I32Array *array, i32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i32_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_i32_array_append_capped(array, *item); + } +} + +void wapp_i32_array_clear(I32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i32 wapp_i32_array_pop(I32Array *array) { + if (!array || array->count == 0) { + return (i32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i32_array_clear(dst); + + i32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i32_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_i32_array_append_capped(dst, *item); + } +} + +I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I32Array) + sizeof(i32) * capacity; + I32Array *array = NULL; + + if (!allocator) { + goto RETURN_I32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I32_ARRAY_ALLOC; + } + + array->items = (i32 *)((u8 *)array + sizeof(I32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I32_ARRAY_ALLOC: + return array; +} + +I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item) { + I32Array *output = array; + + if (!allocator || !array) { + goto RETURN_I32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I32_ARRAY_APPEND_ALLOC; + } + wapp_i32_array_copy_capped(array, output); + } + + wapp_i32_array_append_capped(output, item); + +RETURN_I32_ARRAY_APPEND_ALLOC: + return output; +} + +I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other) { + I32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I32_ARRAY_EXTEND_ALLOC; + } + wapp_i32_array_copy_capped(array, output); + } + + wapp_i32_array_extend_capped(output, other); + +RETURN_I32_ARRAY_EXTEND_ALLOC: + return output; +} + +I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst) { + I32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I32_ARRAY_COPY_ALLOC; + } + } + + wapp_i32_array_clear(output); + wapp_i32_array_copy_capped(src, output); + +RETURN_I32_ARRAY_COPY_ALLOC: + return output; +} + +i64 *wapp_i64_array_get(const I64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i64_array_set(I64Array *array, u64 index, i64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i64_array_append_capped(I64Array *array, i64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i64_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_i64_array_append_capped(array, *item); + } +} + +void wapp_i64_array_clear(I64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i64 wapp_i64_array_pop(I64Array *array) { + if (!array || array->count == 0) { + return (i64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i64_array_clear(dst); + + i64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_i64_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_i64_array_append_capped(dst, *item); + } +} + +I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I64Array) + sizeof(i64) * capacity; + I64Array *array = NULL; + + if (!allocator) { + goto RETURN_I64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I64_ARRAY_ALLOC; + } + + array->items = (i64 *)((u8 *)array + sizeof(I64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I64_ARRAY_ALLOC: + return array; +} + +I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item) { + I64Array *output = array; + + if (!allocator || !array) { + goto RETURN_I64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I64_ARRAY_APPEND_ALLOC; + } + wapp_i64_array_copy_capped(array, output); + } + + wapp_i64_array_append_capped(output, item); + +RETURN_I64_ARRAY_APPEND_ALLOC: + return output; +} + +I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other) { + I64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I64_ARRAY_EXTEND_ALLOC; + } + wapp_i64_array_copy_capped(array, output); + } + + wapp_i64_array_extend_capped(output, other); + +RETURN_I64_ARRAY_EXTEND_ALLOC: + return output; +} + +I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst) { + I64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I64_ARRAY_COPY_ALLOC; + } + } + + wapp_i64_array_clear(output); + wapp_i64_array_copy_capped(src, output); + +RETURN_I64_ARRAY_COPY_ALLOC: + return output; +} + +u8 *wapp_u8_array_get(const U8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u8_array_set(U8Array *array, u64 index, u8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u8_array_append_capped(U8Array *array, u8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u8_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_u8_array_append_capped(array, *item); + } +} + +void wapp_u8_array_clear(U8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u8 wapp_u8_array_pop(U8Array *array) { + if (!array || array->count == 0) { + return (u8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u8_array_clear(dst); + + u8 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u8_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_u8_array_append_capped(dst, *item); + } +} + +U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U8Array) + sizeof(u8) * capacity; + U8Array *array = NULL; + + if (!allocator) { + goto RETURN_U8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U8_ARRAY_ALLOC; + } + + array->items = (u8 *)((u8 *)array + sizeof(U8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U8_ARRAY_ALLOC: + return array; +} + +U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item) { + U8Array *output = array; + + if (!allocator || !array) { + goto RETURN_U8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U8_ARRAY_APPEND_ALLOC; + } + wapp_u8_array_copy_capped(array, output); + } + + wapp_u8_array_append_capped(output, item); + +RETURN_U8_ARRAY_APPEND_ALLOC: + return output; +} + +U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other) { + U8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U8_ARRAY_EXTEND_ALLOC; + } + wapp_u8_array_copy_capped(array, output); + } + + wapp_u8_array_extend_capped(output, other); + +RETURN_U8_ARRAY_EXTEND_ALLOC: + return output; +} + +U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst) { + U8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U8_ARRAY_COPY_ALLOC; + } + } + + wapp_u8_array_clear(output); + wapp_u8_array_copy_capped(src, output); + +RETURN_U8_ARRAY_COPY_ALLOC: + return output; +} + +u16 *wapp_u16_array_get(const U16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u16_array_set(U16Array *array, u64 index, u16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u16_array_append_capped(U16Array *array, u16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u16_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_u16_array_append_capped(array, *item); + } +} + +void wapp_u16_array_clear(U16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u16 wapp_u16_array_pop(U16Array *array) { + if (!array || array->count == 0) { + return (u16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u16_array_clear(dst); + + u16 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u16_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_u16_array_append_capped(dst, *item); + } +} + +U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U16Array) + sizeof(u16) * capacity; + U16Array *array = NULL; + + if (!allocator) { + goto RETURN_U16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U16_ARRAY_ALLOC; + } + + array->items = (u16 *)((u8 *)array + sizeof(U16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U16_ARRAY_ALLOC: + return array; +} + +U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item) { + U16Array *output = array; + + if (!allocator || !array) { + goto RETURN_U16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U16_ARRAY_APPEND_ALLOC; + } + wapp_u16_array_copy_capped(array, output); + } + + wapp_u16_array_append_capped(output, item); + +RETURN_U16_ARRAY_APPEND_ALLOC: + return output; +} + +U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other) { + U16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U16_ARRAY_EXTEND_ALLOC; + } + wapp_u16_array_copy_capped(array, output); + } + + wapp_u16_array_extend_capped(output, other); + +RETURN_U16_ARRAY_EXTEND_ALLOC: + return output; +} + +U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst) { + U16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U16_ARRAY_COPY_ALLOC; + } + } + + wapp_u16_array_clear(output); + wapp_u16_array_copy_capped(src, output); + +RETURN_U16_ARRAY_COPY_ALLOC: + return output; +} + +u32 *wapp_u32_array_get(const U32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u32_array_set(U32Array *array, u64 index, u32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u32_array_append_capped(U32Array *array, u32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u32_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_u32_array_append_capped(array, *item); + } +} + +void wapp_u32_array_clear(U32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u32 wapp_u32_array_pop(U32Array *array) { + if (!array || array->count == 0) { + return (u32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u32_array_clear(dst); + + u32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u32_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_u32_array_append_capped(dst, *item); + } +} + +U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U32Array) + sizeof(u32) * capacity; + U32Array *array = NULL; + + if (!allocator) { + goto RETURN_U32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U32_ARRAY_ALLOC; + } + + array->items = (u32 *)((u8 *)array + sizeof(U32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U32_ARRAY_ALLOC: + return array; +} + +U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item) { + U32Array *output = array; + + if (!allocator || !array) { + goto RETURN_U32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U32_ARRAY_APPEND_ALLOC; + } + wapp_u32_array_copy_capped(array, output); + } + + wapp_u32_array_append_capped(output, item); + +RETURN_U32_ARRAY_APPEND_ALLOC: + return output; +} + +U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other) { + U32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U32_ARRAY_EXTEND_ALLOC; + } + wapp_u32_array_copy_capped(array, output); + } + + wapp_u32_array_extend_capped(output, other); + +RETURN_U32_ARRAY_EXTEND_ALLOC: + return output; +} + +U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst) { + U32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U32_ARRAY_COPY_ALLOC; + } + } + + wapp_u32_array_clear(output); + wapp_u32_array_copy_capped(src, output); + +RETURN_U32_ARRAY_COPY_ALLOC: + return output; +} + +u64 *wapp_u64_array_get(const U64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u64_array_set(U64Array *array, u64 index, u64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u64_array_append_capped(U64Array *array, u64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u64_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_u64_array_append_capped(array, *item); + } +} + +void wapp_u64_array_clear(U64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u64 wapp_u64_array_pop(U64Array *array) { + if (!array || array->count == 0) { + return (u64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u64_array_clear(dst); + + u64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_u64_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_u64_array_append_capped(dst, *item); + } +} + +U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U64Array) + sizeof(u64) * capacity; + U64Array *array = NULL; + + if (!allocator) { + goto RETURN_U64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U64_ARRAY_ALLOC; + } + + array->items = (u64 *)((u8 *)array + sizeof(U64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U64_ARRAY_ALLOC: + return array; +} + +U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item) { + U64Array *output = array; + + if (!allocator || !array) { + goto RETURN_U64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U64_ARRAY_APPEND_ALLOC; + } + wapp_u64_array_copy_capped(array, output); + } + + wapp_u64_array_append_capped(output, item); + +RETURN_U64_ARRAY_APPEND_ALLOC: + return output; +} + +U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other) { + U64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U64_ARRAY_EXTEND_ALLOC; + } + wapp_u64_array_copy_capped(array, output); + } + + wapp_u64_array_extend_capped(output, other); + +RETURN_U64_ARRAY_EXTEND_ALLOC: + return output; +} + +U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst) { + U64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U64_ARRAY_COPY_ALLOC; + } + } + + wapp_u64_array_clear(output); + wapp_u64_array_copy_capped(src, output); + +RETURN_U64_ARRAY_COPY_ALLOC: + return output; +} + +f32 *wapp_f32_array_get(const F32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f32_array_set(F32Array *array, u64 index, f32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f32_array_append_capped(F32Array *array, f32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f32_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_f32_array_append_capped(array, *item); + } +} + +void wapp_f32_array_clear(F32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f32 wapp_f32_array_pop(F32Array *array) { + if (!array || array->count == 0) { + return (f32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f32_array_clear(dst); + + f32 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f32_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_f32_array_append_capped(dst, *item); + } +} + +F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F32Array) + sizeof(f32) * capacity; + F32Array *array = NULL; + + if (!allocator) { + goto RETURN_F32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F32_ARRAY_ALLOC; + } + + array->items = (f32 *)((u8 *)array + sizeof(F32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F32_ARRAY_ALLOC: + return array; +} + +F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item) { + F32Array *output = array; + + if (!allocator || !array) { + goto RETURN_F32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F32_ARRAY_APPEND_ALLOC; + } + wapp_f32_array_copy_capped(array, output); + } + + wapp_f32_array_append_capped(output, item); + +RETURN_F32_ARRAY_APPEND_ALLOC: + return output; +} + +F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other) { + F32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F32_ARRAY_EXTEND_ALLOC; + } + wapp_f32_array_copy_capped(array, output); + } + + wapp_f32_array_extend_capped(output, other); + +RETURN_F32_ARRAY_EXTEND_ALLOC: + return output; +} + +F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst) { + F32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F32_ARRAY_COPY_ALLOC; + } + } + + wapp_f32_array_clear(output); + wapp_f32_array_copy_capped(src, output); + +RETURN_F32_ARRAY_COPY_ALLOC: + return output; +} + +f64 *wapp_f64_array_get(const F64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f64_array_set(F64Array *array, u64 index, f64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f64_array_append_capped(F64Array *array, f64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f64_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_f64_array_append_capped(array, *item); + } +} + +void wapp_f64_array_clear(F64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f64 wapp_f64_array_pop(F64Array *array) { + if (!array || array->count == 0) { + return (f64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f64_array_clear(dst); + + f64 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f64_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_f64_array_append_capped(dst, *item); + } +} + +F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F64Array) + sizeof(f64) * capacity; + F64Array *array = NULL; + + if (!allocator) { + goto RETURN_F64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F64_ARRAY_ALLOC; + } + + array->items = (f64 *)((u8 *)array + sizeof(F64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F64_ARRAY_ALLOC: + return array; +} + +F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item) { + F64Array *output = array; + + if (!allocator || !array) { + goto RETURN_F64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F64_ARRAY_APPEND_ALLOC; + } + wapp_f64_array_copy_capped(array, output); + } + + wapp_f64_array_append_capped(output, item); + +RETURN_F64_ARRAY_APPEND_ALLOC: + return output; +} + +F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other) { + F64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F64_ARRAY_EXTEND_ALLOC; + } + wapp_f64_array_copy_capped(array, output); + } + + wapp_f64_array_extend_capped(output, other); + +RETURN_F64_ARRAY_EXTEND_ALLOC: + return output; +} + +F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst) { + F64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F64_ARRAY_COPY_ALLOC; + } + } + + wapp_f64_array_clear(output); + wapp_f64_array_copy_capped(src, output); + +RETURN_F64_ARRAY_COPY_ALLOC: + return output; +} + +f128 *wapp_f128_array_get(const F128Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f128_array_set(F128Array *array, u64 index, f128 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f128_array_append_capped(F128Array *array, f128 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f128 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f128_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_f128_array_append_capped(array, *item); + } +} + +void wapp_f128_array_clear(F128Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f128 wapp_f128_array_pop(F128Array *array) { + if (!array || array->count == 0) { + return (f128){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f128_array_clear(dst); + + f128 *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_f128_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_f128_array_append_capped(dst, *item); + } +} + +F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F128Array) + sizeof(f128) * capacity; + F128Array *array = NULL; + + if (!allocator) { + goto RETURN_F128_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F128_ARRAY_ALLOC; + } + + array->items = (f128 *)((u8 *)array + sizeof(F128Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F128_ARRAY_ALLOC: + return array; +} + +F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item) { + F128Array *output = array; + + if (!allocator || !array) { + goto RETURN_F128_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F128_ARRAY_APPEND_ALLOC; + } + wapp_f128_array_copy_capped(array, output); + } + + wapp_f128_array_append_capped(output, item); + +RETURN_F128_ARRAY_APPEND_ALLOC: + return output; +} + +F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other) { + F128Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F128_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F128_ARRAY_EXTEND_ALLOC; + } + wapp_f128_array_copy_capped(array, output); + } + + wapp_f128_array_extend_capped(output, other); + +RETURN_F128_ARRAY_EXTEND_ALLOC: + return output; +} + +F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst) { + F128Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F128_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F128_ARRAY_COPY_ALLOC; + } + } + + wapp_f128_array_clear(output); + wapp_f128_array_copy_capped(src, output); + +RETURN_F128_ARRAY_COPY_ALLOC: + return output; +} + +iptr *wapp_iptr_array_get(const IptrArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_iptr_array_append_capped(IptrArray *array, iptr item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + iptr *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_iptr_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_iptr_array_append_capped(array, *item); + } +} + +void wapp_iptr_array_clear(IptrArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +iptr wapp_iptr_array_pop(IptrArray *array) { + if (!array || array->count == 0) { + return (iptr){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst) { + if (!src || !dst) { + return; + } + + wapp_iptr_array_clear(dst); + + iptr *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_iptr_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_iptr_array_append_capped(dst, *item); + } +} + +IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(IptrArray) + sizeof(iptr) * capacity; + IptrArray *array = NULL; + + if (!allocator) { + goto RETURN_IPTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_IPTR_ARRAY_ALLOC; + } + + array->items = (iptr *)((u8 *)array + sizeof(IptrArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_IPTR_ARRAY_ALLOC: + return array; +} + +IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item) { + IptrArray *output = array; + + if (!allocator || !array) { + goto RETURN_IPTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_IPTR_ARRAY_APPEND_ALLOC; + } + wapp_iptr_array_copy_capped(array, output); + } + + wapp_iptr_array_append_capped(output, item); + +RETURN_IPTR_ARRAY_APPEND_ALLOC: + return output; +} + +IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other) { + IptrArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; + } + wapp_iptr_array_copy_capped(array, output); + } + + wapp_iptr_array_extend_capped(output, other); + +RETURN_IPTR_ARRAY_EXTEND_ALLOC: + return output; +} + +IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst) { + IptrArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_IPTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_IPTR_ARRAY_COPY_ALLOC; + } + } + + wapp_iptr_array_clear(output); + wapp_iptr_array_copy_capped(src, output); + +RETURN_IPTR_ARRAY_COPY_ALLOC: + return output; +} + +uptr *wapp_uptr_array_get(const UptrArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_uptr_array_append_capped(UptrArray *array, uptr item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + uptr *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 items_to_add = other->count; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_uptr_array_get(other, item_index); + ++item_index; + running = item_index < items_to_add; + + if (!item) { + continue; + } + + wapp_uptr_array_append_capped(array, *item); + } +} + +void wapp_uptr_array_clear(UptrArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +uptr wapp_uptr_array_pop(UptrArray *array) { + if (!array || array->count == 0) { + return (uptr){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst) { + if (!src || !dst) { + return; + } + + wapp_uptr_array_clear(dst); + + uptr *item; + + // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of + // MSVC Spectre mitigation warnings + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + u64 item_index = 0; + bool running = true; + while (running) { + item = wapp_uptr_array_get(src, item_index); + ++item_index; + running = item_index < to_copy; + + if (!item) { + continue; + } + + wapp_uptr_array_append_capped(dst, *item); + } +} + +UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(UptrArray) + sizeof(uptr) * capacity; + UptrArray *array = NULL; + + if (!allocator) { + goto RETURN_UPTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_UPTR_ARRAY_ALLOC; + } + + array->items = (uptr *)((u8 *)array + sizeof(UptrArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_UPTR_ARRAY_ALLOC: + return array; +} + +UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item) { + UptrArray *output = array; + + if (!allocator || !array) { + goto RETURN_UPTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_UPTR_ARRAY_APPEND_ALLOC; + } + wapp_uptr_array_copy_capped(array, output); + } + + wapp_uptr_array_append_capped(output, item); + +RETURN_UPTR_ARRAY_APPEND_ALLOC: + return output; +} + +UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other) { + UptrArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; + } + wapp_uptr_array_copy_capped(array, output); + } + + wapp_uptr_array_extend_capped(output, other); + +RETURN_UPTR_ARRAY_EXTEND_ALLOC: + return output; +} + +UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst) { + UptrArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_UPTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_UPTR_ARRAY_COPY_ALLOC; + } + } + + wapp_uptr_array_clear(output); + wapp_uptr_array_copy_capped(src, output); + +RETURN_UPTR_ARRAY_COPY_ALLOC: + return output; +} + diff --git a/src/primitives/array/array.h b/src/primitives/array/array.h index 5035072..70906b1 100644 --- a/src/primitives/array/array.h +++ b/src/primitives/array/array.h @@ -1,505 +1,505 @@ -/** - * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN - */ - -#ifndef ARRAY_H -#define ARRAY_H - -#include "../mem_allocator/mem_allocator.h" -#include "../strings/str8/str8.h" -#include "../../common/misc/misc_utils.h" -#include "../../common/aliases/aliases.h" -#include "../../common/platform/platform.h" -#include - -#ifdef WAPP_PLATFORM_CPP -BEGIN_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -#define wapp_str8_array(...) ((Str8Array){ \ - .items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2) \ -}) -#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_void_ptr_array(...) ((VoidPArray){ \ - .items = (void *[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2) \ -}) -#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_bool_array(...) ((BoolArray){ \ - .items = (bool[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(bool, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2) \ -}) -#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_char_array(...) ((CharArray){ \ - .items = (char[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(char, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2) \ -}) -#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_c8_array(...) ((C8Array){ \ - .items = (c8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(c8, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2) \ -}) -#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_c16_array(...) ((C16Array){ \ - .items = (c16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(c16, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2) \ -}) -#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_c32_array(...) ((C32Array){ \ - .items = (c32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(c32, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2) \ -}) -#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_i8_array(...) ((I8Array){ \ - .items = (i8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(i8, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2) \ -}) -#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_i16_array(...) ((I16Array){ \ - .items = (i16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(i16, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2) \ -}) -#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_i32_array(...) ((I32Array){ \ - .items = (i32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2) \ -}) -#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_i64_array(...) ((I64Array){ \ - .items = (i64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(i64, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2) \ -}) -#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_u8_array(...) ((U8Array){ \ - .items = (u8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(u8, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2) \ -}) -#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_u16_array(...) ((U16Array){ \ - .items = (u16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(u16, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2) \ -}) -#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_u32_array(...) ((U32Array){ \ - .items = (u32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(u32, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2) \ -}) -#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_u64_array(...) ((U64Array){ \ - .items = (u64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(u64, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2) \ -}) -#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_f32_array(...) ((F32Array){ \ - .items = (f32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(f32, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2) \ -}) -#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_f64_array(...) ((F64Array){ \ - .items = (f64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(f64, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2) \ -}) -#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_f128_array(...) ((F128Array){ \ - .items = (f128[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(f128, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2) \ -}) -#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_iptr_array(...) ((IptrArray){ \ - .items = (iptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(iptr, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2) \ -}) -#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) -#define wapp_uptr_array(...) ((UptrArray){ \ - .items = (uptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ - .count = wapp_misc_utils_va_args_count(uptr, __VA_ARGS__), \ - .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2) \ -}) -#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) - -typedef struct Str8Array Str8Array; -struct Str8Array { - Str8 *items; - u64 count; - u64 capacity; -}; - -typedef struct VoidPArray VoidPArray; -struct VoidPArray { - void * *items; - u64 count; - u64 capacity; -}; - -typedef struct BoolArray BoolArray; -struct BoolArray { - bool *items; - u64 count; - u64 capacity; -}; - -typedef struct CharArray CharArray; -struct CharArray { - char *items; - u64 count; - u64 capacity; -}; - -typedef struct C8Array C8Array; -struct C8Array { - c8 *items; - u64 count; - u64 capacity; -}; - -typedef struct C16Array C16Array; -struct C16Array { - c16 *items; - u64 count; - u64 capacity; -}; - -typedef struct C32Array C32Array; -struct C32Array { - c32 *items; - u64 count; - u64 capacity; -}; - -typedef struct I8Array I8Array; -struct I8Array { - i8 *items; - u64 count; - u64 capacity; -}; - -typedef struct I16Array I16Array; -struct I16Array { - i16 *items; - u64 count; - u64 capacity; -}; - -typedef struct I32Array I32Array; -struct I32Array { - i32 *items; - u64 count; - u64 capacity; -}; - -typedef struct I64Array I64Array; -struct I64Array { - i64 *items; - u64 count; - u64 capacity; -}; - -typedef struct U8Array U8Array; -struct U8Array { - u8 *items; - u64 count; - u64 capacity; -}; - -typedef struct U16Array U16Array; -struct U16Array { - u16 *items; - u64 count; - u64 capacity; -}; - -typedef struct U32Array U32Array; -struct U32Array { - u32 *items; - u64 count; - u64 capacity; -}; - -typedef struct U64Array U64Array; -struct U64Array { - u64 *items; - u64 count; - u64 capacity; -}; - -typedef struct F32Array F32Array; -struct F32Array { - f32 *items; - u64 count; - u64 capacity; -}; - -typedef struct F64Array F64Array; -struct F64Array { - f64 *items; - u64 count; - u64 capacity; -}; - -typedef struct F128Array F128Array; -struct F128Array { - f128 *items; - u64 count; - u64 capacity; -}; - -typedef struct IptrArray IptrArray; -struct IptrArray { - iptr *items; - u64 count; - u64 capacity; -}; - -typedef struct UptrArray UptrArray; -struct UptrArray { - uptr *items; - u64 count; - u64 capacity; -}; - -Str8 *wapp_str8_array_get(const Str8Array *array, u64 index); -void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item); -void wapp_str8_array_append_capped(Str8Array *array, Str8 item); -void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other); -void wapp_str8_array_clear(Str8Array *array); -Str8 wapp_str8_array_pop(Str8Array *array); -void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst); -Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity); -Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item); -Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other); -Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst); -void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index); -void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item); -void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item); -void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other); -void wapp_void_ptr_array_clear(VoidPArray *array); -void * wapp_void_ptr_array_pop(VoidPArray *array); -void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst); -VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); -VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item); -VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other); -VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst); -bool *wapp_bool_array_get(const BoolArray *array, u64 index); -void wapp_bool_array_set(BoolArray *array, u64 index, bool item); -void wapp_bool_array_append_capped(BoolArray *array, bool item); -void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other); -void wapp_bool_array_clear(BoolArray *array); -bool wapp_bool_array_pop(BoolArray *array); -void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst); -BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity); -BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item); -BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other); -BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst); -char *wapp_char_array_get(const CharArray *array, u64 index); -void wapp_char_array_set(CharArray *array, u64 index, char item); -void wapp_char_array_append_capped(CharArray *array, char item); -void wapp_char_array_extend_capped(CharArray *array, const CharArray *other); -void wapp_char_array_clear(CharArray *array); -char wapp_char_array_pop(CharArray *array); -void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst); -CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity); -CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item); -CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other); -CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst); -c8 *wapp_c8_array_get(const C8Array *array, u64 index); -void wapp_c8_array_set(C8Array *array, u64 index, c8 item); -void wapp_c8_array_append_capped(C8Array *array, c8 item); -void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other); -void wapp_c8_array_clear(C8Array *array); -c8 wapp_c8_array_pop(C8Array *array); -void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst); -C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity); -C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item); -C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other); -C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst); -c16 *wapp_c16_array_get(const C16Array *array, u64 index); -void wapp_c16_array_set(C16Array *array, u64 index, c16 item); -void wapp_c16_array_append_capped(C16Array *array, c16 item); -void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other); -void wapp_c16_array_clear(C16Array *array); -c16 wapp_c16_array_pop(C16Array *array); -void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst); -C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity); -C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item); -C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other); -C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst); -c32 *wapp_c32_array_get(const C32Array *array, u64 index); -void wapp_c32_array_set(C32Array *array, u64 index, c32 item); -void wapp_c32_array_append_capped(C32Array *array, c32 item); -void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other); -void wapp_c32_array_clear(C32Array *array); -c32 wapp_c32_array_pop(C32Array *array); -void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst); -C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity); -C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item); -C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other); -C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst); -i8 *wapp_i8_array_get(const I8Array *array, u64 index); -void wapp_i8_array_set(I8Array *array, u64 index, i8 item); -void wapp_i8_array_append_capped(I8Array *array, i8 item); -void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other); -void wapp_i8_array_clear(I8Array *array); -i8 wapp_i8_array_pop(I8Array *array); -void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst); -I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity); -I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item); -I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other); -I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst); -i16 *wapp_i16_array_get(const I16Array *array, u64 index); -void wapp_i16_array_set(I16Array *array, u64 index, i16 item); -void wapp_i16_array_append_capped(I16Array *array, i16 item); -void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other); -void wapp_i16_array_clear(I16Array *array); -i16 wapp_i16_array_pop(I16Array *array); -void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst); -I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity); -I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item); -I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other); -I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst); -i32 *wapp_i32_array_get(const I32Array *array, u64 index); -void wapp_i32_array_set(I32Array *array, u64 index, i32 item); -void wapp_i32_array_append_capped(I32Array *array, i32 item); -void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other); -void wapp_i32_array_clear(I32Array *array); -i32 wapp_i32_array_pop(I32Array *array); -void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst); -I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity); -I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item); -I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other); -I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst); -i64 *wapp_i64_array_get(const I64Array *array, u64 index); -void wapp_i64_array_set(I64Array *array, u64 index, i64 item); -void wapp_i64_array_append_capped(I64Array *array, i64 item); -void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other); -void wapp_i64_array_clear(I64Array *array); -i64 wapp_i64_array_pop(I64Array *array); -void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst); -I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity); -I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item); -I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other); -I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst); -u8 *wapp_u8_array_get(const U8Array *array, u64 index); -void wapp_u8_array_set(U8Array *array, u64 index, u8 item); -void wapp_u8_array_append_capped(U8Array *array, u8 item); -void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other); -void wapp_u8_array_clear(U8Array *array); -u8 wapp_u8_array_pop(U8Array *array); -void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst); -U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity); -U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item); -U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other); -U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst); -u16 *wapp_u16_array_get(const U16Array *array, u64 index); -void wapp_u16_array_set(U16Array *array, u64 index, u16 item); -void wapp_u16_array_append_capped(U16Array *array, u16 item); -void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other); -void wapp_u16_array_clear(U16Array *array); -u16 wapp_u16_array_pop(U16Array *array); -void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst); -U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity); -U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item); -U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other); -U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst); -u32 *wapp_u32_array_get(const U32Array *array, u64 index); -void wapp_u32_array_set(U32Array *array, u64 index, u32 item); -void wapp_u32_array_append_capped(U32Array *array, u32 item); -void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other); -void wapp_u32_array_clear(U32Array *array); -u32 wapp_u32_array_pop(U32Array *array); -void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst); -U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity); -U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item); -U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other); -U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst); -u64 *wapp_u64_array_get(const U64Array *array, u64 index); -void wapp_u64_array_set(U64Array *array, u64 index, u64 item); -void wapp_u64_array_append_capped(U64Array *array, u64 item); -void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other); -void wapp_u64_array_clear(U64Array *array); -u64 wapp_u64_array_pop(U64Array *array); -void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst); -U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity); -U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item); -U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other); -U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst); -f32 *wapp_f32_array_get(const F32Array *array, u64 index); -void wapp_f32_array_set(F32Array *array, u64 index, f32 item); -void wapp_f32_array_append_capped(F32Array *array, f32 item); -void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other); -void wapp_f32_array_clear(F32Array *array); -f32 wapp_f32_array_pop(F32Array *array); -void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst); -F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity); -F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item); -F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other); -F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst); -f64 *wapp_f64_array_get(const F64Array *array, u64 index); -void wapp_f64_array_set(F64Array *array, u64 index, f64 item); -void wapp_f64_array_append_capped(F64Array *array, f64 item); -void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other); -void wapp_f64_array_clear(F64Array *array); -f64 wapp_f64_array_pop(F64Array *array); -void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst); -F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity); -F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item); -F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other); -F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst); -f128 *wapp_f128_array_get(const F128Array *array, u64 index); -void wapp_f128_array_set(F128Array *array, u64 index, f128 item); -void wapp_f128_array_append_capped(F128Array *array, f128 item); -void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other); -void wapp_f128_array_clear(F128Array *array); -f128 wapp_f128_array_pop(F128Array *array); -void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst); -F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity); -F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item); -F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other); -F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst); -iptr *wapp_iptr_array_get(const IptrArray *array, u64 index); -void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item); -void wapp_iptr_array_append_capped(IptrArray *array, iptr item); -void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other); -void wapp_iptr_array_clear(IptrArray *array); -iptr wapp_iptr_array_pop(IptrArray *array); -void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst); -IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); -IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item); -IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other); -IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst); -uptr *wapp_uptr_array_get(const UptrArray *array, u64 index); -void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item); -void wapp_uptr_array_append_capped(UptrArray *array, uptr item); -void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other); -void wapp_uptr_array_clear(UptrArray *array); -uptr wapp_uptr_array_pop(UptrArray *array); -void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst); -UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); -UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item); -UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other); -UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst); - -#ifdef WAPP_PLATFORM_CPP -END_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -#endif // !ARRAY_H +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#ifndef ARRAY_H +#define ARRAY_H + +#include "../mem_allocator/mem_allocator.h" +#include "../strings/str8/str8.h" +#include "../../common/misc/misc_utils.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include + +#ifdef WAPP_PLATFORM_CPP +BEGIN_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#define wapp_str8_array(...) ((Str8Array){ \ + .items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2) \ +}) +#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_void_ptr_array(...) ((VoidPArray){ \ + .items = (void *[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2) \ +}) +#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_bool_array(...) ((BoolArray){ \ + .items = (bool[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(bool, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2) \ +}) +#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_char_array(...) ((CharArray){ \ + .items = (char[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(char, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2) \ +}) +#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c8_array(...) ((C8Array){ \ + .items = (c8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2) \ +}) +#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c16_array(...) ((C16Array){ \ + .items = (c16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2) \ +}) +#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c32_array(...) ((C32Array){ \ + .items = (c32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2) \ +}) +#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i8_array(...) ((I8Array){ \ + .items = (i8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2) \ +}) +#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i16_array(...) ((I16Array){ \ + .items = (i16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2) \ +}) +#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i32_array(...) ((I32Array){ \ + .items = (i32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2) \ +}) +#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i64_array(...) ((I64Array){ \ + .items = (i64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2) \ +}) +#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u8_array(...) ((U8Array){ \ + .items = (u8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2) \ +}) +#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u16_array(...) ((U16Array){ \ + .items = (u16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2) \ +}) +#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u32_array(...) ((U32Array){ \ + .items = (u32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2) \ +}) +#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u64_array(...) ((U64Array){ \ + .items = (u64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2) \ +}) +#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f32_array(...) ((F32Array){ \ + .items = (f32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2) \ +}) +#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f64_array(...) ((F64Array){ \ + .items = (f64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2) \ +}) +#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f128_array(...) ((F128Array){ \ + .items = (f128[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f128, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2) \ +}) +#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_iptr_array(...) ((IptrArray){ \ + .items = (iptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(iptr, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2) \ +}) +#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_uptr_array(...) ((UptrArray){ \ + .items = (uptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(uptr, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2) \ +}) +#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) + +typedef struct Str8Array Str8Array; +struct Str8Array { + Str8 *items; + u64 count; + u64 capacity; +}; + +typedef struct VoidPArray VoidPArray; +struct VoidPArray { + void * *items; + u64 count; + u64 capacity; +}; + +typedef struct BoolArray BoolArray; +struct BoolArray { + bool *items; + u64 count; + u64 capacity; +}; + +typedef struct CharArray CharArray; +struct CharArray { + char *items; + u64 count; + u64 capacity; +}; + +typedef struct C8Array C8Array; +struct C8Array { + c8 *items; + u64 count; + u64 capacity; +}; + +typedef struct C16Array C16Array; +struct C16Array { + c16 *items; + u64 count; + u64 capacity; +}; + +typedef struct C32Array C32Array; +struct C32Array { + c32 *items; + u64 count; + u64 capacity; +}; + +typedef struct I8Array I8Array; +struct I8Array { + i8 *items; + u64 count; + u64 capacity; +}; + +typedef struct I16Array I16Array; +struct I16Array { + i16 *items; + u64 count; + u64 capacity; +}; + +typedef struct I32Array I32Array; +struct I32Array { + i32 *items; + u64 count; + u64 capacity; +}; + +typedef struct I64Array I64Array; +struct I64Array { + i64 *items; + u64 count; + u64 capacity; +}; + +typedef struct U8Array U8Array; +struct U8Array { + u8 *items; + u64 count; + u64 capacity; +}; + +typedef struct U16Array U16Array; +struct U16Array { + u16 *items; + u64 count; + u64 capacity; +}; + +typedef struct U32Array U32Array; +struct U32Array { + u32 *items; + u64 count; + u64 capacity; +}; + +typedef struct U64Array U64Array; +struct U64Array { + u64 *items; + u64 count; + u64 capacity; +}; + +typedef struct F32Array F32Array; +struct F32Array { + f32 *items; + u64 count; + u64 capacity; +}; + +typedef struct F64Array F64Array; +struct F64Array { + f64 *items; + u64 count; + u64 capacity; +}; + +typedef struct F128Array F128Array; +struct F128Array { + f128 *items; + u64 count; + u64 capacity; +}; + +typedef struct IptrArray IptrArray; +struct IptrArray { + iptr *items; + u64 count; + u64 capacity; +}; + +typedef struct UptrArray UptrArray; +struct UptrArray { + uptr *items; + u64 count; + u64 capacity; +}; + +Str8 *wapp_str8_array_get(const Str8Array *array, u64 index); +void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item); +void wapp_str8_array_append_capped(Str8Array *array, Str8 item); +void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other); +void wapp_str8_array_clear(Str8Array *array); +Str8 wapp_str8_array_pop(Str8Array *array); +void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst); +Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item); +Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other); +Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst); +void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index); +void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item); +void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item); +void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other); +void wapp_void_ptr_array_clear(VoidPArray *array); +void * wapp_void_ptr_array_pop(VoidPArray *array); +void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst); +VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item); +VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other); +VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst); +bool *wapp_bool_array_get(const BoolArray *array, u64 index); +void wapp_bool_array_set(BoolArray *array, u64 index, bool item); +void wapp_bool_array_append_capped(BoolArray *array, bool item); +void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other); +void wapp_bool_array_clear(BoolArray *array); +bool wapp_bool_array_pop(BoolArray *array); +void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst); +BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity); +BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item); +BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other); +BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst); +char *wapp_char_array_get(const CharArray *array, u64 index); +void wapp_char_array_set(CharArray *array, u64 index, char item); +void wapp_char_array_append_capped(CharArray *array, char item); +void wapp_char_array_extend_capped(CharArray *array, const CharArray *other); +void wapp_char_array_clear(CharArray *array); +char wapp_char_array_pop(CharArray *array); +void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst); +CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity); +CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item); +CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other); +CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst); +c8 *wapp_c8_array_get(const C8Array *array, u64 index); +void wapp_c8_array_set(C8Array *array, u64 index, c8 item); +void wapp_c8_array_append_capped(C8Array *array, c8 item); +void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other); +void wapp_c8_array_clear(C8Array *array); +c8 wapp_c8_array_pop(C8Array *array); +void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst); +C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item); +C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other); +C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst); +c16 *wapp_c16_array_get(const C16Array *array, u64 index); +void wapp_c16_array_set(C16Array *array, u64 index, c16 item); +void wapp_c16_array_append_capped(C16Array *array, c16 item); +void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other); +void wapp_c16_array_clear(C16Array *array); +c16 wapp_c16_array_pop(C16Array *array); +void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst); +C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item); +C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other); +C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst); +c32 *wapp_c32_array_get(const C32Array *array, u64 index); +void wapp_c32_array_set(C32Array *array, u64 index, c32 item); +void wapp_c32_array_append_capped(C32Array *array, c32 item); +void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other); +void wapp_c32_array_clear(C32Array *array); +c32 wapp_c32_array_pop(C32Array *array); +void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst); +C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item); +C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other); +C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst); +i8 *wapp_i8_array_get(const I8Array *array, u64 index); +void wapp_i8_array_set(I8Array *array, u64 index, i8 item); +void wapp_i8_array_append_capped(I8Array *array, i8 item); +void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other); +void wapp_i8_array_clear(I8Array *array); +i8 wapp_i8_array_pop(I8Array *array); +void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst); +I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item); +I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other); +I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst); +i16 *wapp_i16_array_get(const I16Array *array, u64 index); +void wapp_i16_array_set(I16Array *array, u64 index, i16 item); +void wapp_i16_array_append_capped(I16Array *array, i16 item); +void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other); +void wapp_i16_array_clear(I16Array *array); +i16 wapp_i16_array_pop(I16Array *array); +void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst); +I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item); +I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other); +I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst); +i32 *wapp_i32_array_get(const I32Array *array, u64 index); +void wapp_i32_array_set(I32Array *array, u64 index, i32 item); +void wapp_i32_array_append_capped(I32Array *array, i32 item); +void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other); +void wapp_i32_array_clear(I32Array *array); +i32 wapp_i32_array_pop(I32Array *array); +void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst); +I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item); +I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other); +I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst); +i64 *wapp_i64_array_get(const I64Array *array, u64 index); +void wapp_i64_array_set(I64Array *array, u64 index, i64 item); +void wapp_i64_array_append_capped(I64Array *array, i64 item); +void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other); +void wapp_i64_array_clear(I64Array *array); +i64 wapp_i64_array_pop(I64Array *array); +void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst); +I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item); +I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other); +I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst); +u8 *wapp_u8_array_get(const U8Array *array, u64 index); +void wapp_u8_array_set(U8Array *array, u64 index, u8 item); +void wapp_u8_array_append_capped(U8Array *array, u8 item); +void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other); +void wapp_u8_array_clear(U8Array *array); +u8 wapp_u8_array_pop(U8Array *array); +void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst); +U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item); +U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other); +U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst); +u16 *wapp_u16_array_get(const U16Array *array, u64 index); +void wapp_u16_array_set(U16Array *array, u64 index, u16 item); +void wapp_u16_array_append_capped(U16Array *array, u16 item); +void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other); +void wapp_u16_array_clear(U16Array *array); +u16 wapp_u16_array_pop(U16Array *array); +void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst); +U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item); +U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other); +U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst); +u32 *wapp_u32_array_get(const U32Array *array, u64 index); +void wapp_u32_array_set(U32Array *array, u64 index, u32 item); +void wapp_u32_array_append_capped(U32Array *array, u32 item); +void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other); +void wapp_u32_array_clear(U32Array *array); +u32 wapp_u32_array_pop(U32Array *array); +void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst); +U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item); +U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other); +U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst); +u64 *wapp_u64_array_get(const U64Array *array, u64 index); +void wapp_u64_array_set(U64Array *array, u64 index, u64 item); +void wapp_u64_array_append_capped(U64Array *array, u64 item); +void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other); +void wapp_u64_array_clear(U64Array *array); +u64 wapp_u64_array_pop(U64Array *array); +void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst); +U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item); +U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other); +U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst); +f32 *wapp_f32_array_get(const F32Array *array, u64 index); +void wapp_f32_array_set(F32Array *array, u64 index, f32 item); +void wapp_f32_array_append_capped(F32Array *array, f32 item); +void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other); +void wapp_f32_array_clear(F32Array *array); +f32 wapp_f32_array_pop(F32Array *array); +void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst); +F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item); +F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other); +F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst); +f64 *wapp_f64_array_get(const F64Array *array, u64 index); +void wapp_f64_array_set(F64Array *array, u64 index, f64 item); +void wapp_f64_array_append_capped(F64Array *array, f64 item); +void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other); +void wapp_f64_array_clear(F64Array *array); +f64 wapp_f64_array_pop(F64Array *array); +void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst); +F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item); +F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other); +F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst); +f128 *wapp_f128_array_get(const F128Array *array, u64 index); +void wapp_f128_array_set(F128Array *array, u64 index, f128 item); +void wapp_f128_array_append_capped(F128Array *array, f128 item); +void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other); +void wapp_f128_array_clear(F128Array *array); +f128 wapp_f128_array_pop(F128Array *array); +void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst); +F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item); +F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other); +F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst); +iptr *wapp_iptr_array_get(const IptrArray *array, u64 index); +void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item); +void wapp_iptr_array_append_capped(IptrArray *array, iptr item); +void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other); +void wapp_iptr_array_clear(IptrArray *array); +iptr wapp_iptr_array_pop(IptrArray *array); +void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst); +IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item); +IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other); +IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst); +uptr *wapp_uptr_array_get(const UptrArray *array, u64 index); +void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item); +void wapp_uptr_array_append_capped(UptrArray *array, uptr item); +void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other); +void wapp_uptr_array_clear(UptrArray *array); +uptr wapp_uptr_array_pop(UptrArray *array); +void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst); +UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item); +UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other); +UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst); + +#ifdef WAPP_PLATFORM_CPP +END_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#endif // !ARRAY_H diff --git a/src/primitives/dbl_list/dbl_list.c b/src/primitives/dbl_list/dbl_list.c index d3b4068..96c135d 100644 --- a/src/primitives/dbl_list/dbl_list.c +++ b/src/primitives/dbl_list/dbl_list.c @@ -1,3951 +1,3951 @@ -/** - * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN - */ - -#include "./dbl_list.h" -#include "../../common/aliases/aliases.h" -#include "../../common/platform/platform.h" -#include -#include - -internal Str8List str8_node_to_list(Str8Node *node); -internal VoidPList void_ptr_node_to_list(VoidPNode *node); -internal BoolList bool_node_to_list(BoolNode *node); -internal CharList char_node_to_list(CharNode *node); -internal C8List c8_node_to_list(C8Node *node); -internal C16List c16_node_to_list(C16Node *node); -internal C32List c32_node_to_list(C32Node *node); -internal I8List i8_node_to_list(I8Node *node); -internal I16List i16_node_to_list(I16Node *node); -internal I32List i32_node_to_list(I32Node *node); -internal I64List i64_node_to_list(I64Node *node); -internal U8List u8_node_to_list(U8Node *node); -internal U16List u16_node_to_list(U16Node *node); -internal U32List u32_node_to_list(U32Node *node); -internal U64List u64_node_to_list(U64Node *node); -internal F32List f32_node_to_list(F32Node *node); -internal F64List f64_node_to_list(F64Node *node); -internal F128List f128_node_to_list(F128Node *node); -internal IptrList iptr_node_to_list(IptrNode *node); -internal UptrList uptr_node_to_list(UptrNode *node); - -Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - Str8Node *output = NULL; - Str8Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - Str8List node_list = str8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - Str8Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - Str8List node_list = str8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - Str8Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_str8_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_str8_list_push_back(list, node); - return; - } - - Str8Node *dst_node = wapp_str8_list_get(list, index); - if (!dst_node) { - return; - } - - Str8List node_list = str8_node_to_list(node); - - list->node_count += node_list.node_count; - - Str8Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -Str8Node *wapp_str8_list_pop_front(Str8List *list) { - Str8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_STR8_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (Str8List){0}; - goto RETURN_STR8_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_STR8_LIST_POP_FRONT: - return output; -} - -Str8Node *wapp_str8_list_pop_back(Str8List *list) { - Str8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_STR8_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (Str8List){0}; - goto RETURN_STR8_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_STR8_LIST_POP_BACK: - return output; -} - -Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { - Str8Node *output = NULL; - if (!list) { - goto RETURN_STR8_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_str8_list_pop_front(list); - goto RETURN_STR8_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_str8_list_pop_back(list); - goto RETURN_STR8_LIST_REMOVE; - } - - output = wapp_str8_list_get(list, index); - if (!output) { - goto RETURN_STR8_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_STR8_LIST_REMOVE: - return output; -} - -void wapp_str8_list_empty(Str8List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_str8_list_pop_back(list); - } -} - -VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - VoidPNode *output = NULL; - VoidPNode *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - VoidPList node_list = void_ptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - VoidPNode *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - VoidPList node_list = void_ptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - VoidPNode *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_void_ptr_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_void_ptr_list_push_back(list, node); - return; - } - - VoidPNode *dst_node = wapp_void_ptr_list_get(list, index); - if (!dst_node) { - return; - } - - VoidPList node_list = void_ptr_node_to_list(node); - - list->node_count += node_list.node_count; - - VoidPNode *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list) { - VoidPNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_VOID_PTR_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (VoidPList){0}; - goto RETURN_VOID_PTR_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_VOID_PTR_LIST_POP_FRONT: - return output; -} - -VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list) { - VoidPNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_VOID_PTR_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (VoidPList){0}; - goto RETURN_VOID_PTR_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_VOID_PTR_LIST_POP_BACK: - return output; -} - -VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index) { - VoidPNode *output = NULL; - if (!list) { - goto RETURN_VOID_PTR_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_void_ptr_list_pop_front(list); - goto RETURN_VOID_PTR_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_void_ptr_list_pop_back(list); - goto RETURN_VOID_PTR_LIST_REMOVE; - } - - output = wapp_void_ptr_list_get(list, index); - if (!output) { - goto RETURN_VOID_PTR_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_VOID_PTR_LIST_REMOVE: - return output; -} - -void wapp_void_ptr_list_empty(VoidPList *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_void_ptr_list_pop_back(list); - } -} - -BoolNode *wapp_bool_list_get(const BoolList *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - BoolNode *output = NULL; - BoolNode *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_bool_list_push_front(BoolList *list, BoolNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - BoolList node_list = bool_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - BoolNode *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_bool_list_push_back(BoolList *list, BoolNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - BoolList node_list = bool_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - BoolNode *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_bool_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_bool_list_push_back(list, node); - return; - } - - BoolNode *dst_node = wapp_bool_list_get(list, index); - if (!dst_node) { - return; - } - - BoolList node_list = bool_node_to_list(node); - - list->node_count += node_list.node_count; - - BoolNode *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -BoolNode *wapp_bool_list_pop_front(BoolList *list) { - BoolNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_BOOL_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (BoolList){0}; - goto RETURN_BOOL_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_BOOL_LIST_POP_FRONT: - return output; -} - -BoolNode *wapp_bool_list_pop_back(BoolList *list) { - BoolNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_BOOL_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (BoolList){0}; - goto RETURN_BOOL_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_BOOL_LIST_POP_BACK: - return output; -} - -BoolNode *wapp_bool_list_remove(BoolList *list, u64 index) { - BoolNode *output = NULL; - if (!list) { - goto RETURN_BOOL_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_bool_list_pop_front(list); - goto RETURN_BOOL_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_bool_list_pop_back(list); - goto RETURN_BOOL_LIST_REMOVE; - } - - output = wapp_bool_list_get(list, index); - if (!output) { - goto RETURN_BOOL_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_BOOL_LIST_REMOVE: - return output; -} - -void wapp_bool_list_empty(BoolList *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_bool_list_pop_back(list); - } -} - -CharNode *wapp_char_list_get(const CharList *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - CharNode *output = NULL; - CharNode *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_char_list_push_front(CharList *list, CharNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - CharList node_list = char_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - CharNode *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_char_list_push_back(CharList *list, CharNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - CharList node_list = char_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - CharNode *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_char_list_insert(CharList *list, CharNode *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_char_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_char_list_push_back(list, node); - return; - } - - CharNode *dst_node = wapp_char_list_get(list, index); - if (!dst_node) { - return; - } - - CharList node_list = char_node_to_list(node); - - list->node_count += node_list.node_count; - - CharNode *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -CharNode *wapp_char_list_pop_front(CharList *list) { - CharNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_CHAR_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (CharList){0}; - goto RETURN_CHAR_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_CHAR_LIST_POP_FRONT: - return output; -} - -CharNode *wapp_char_list_pop_back(CharList *list) { - CharNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_CHAR_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (CharList){0}; - goto RETURN_CHAR_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_CHAR_LIST_POP_BACK: - return output; -} - -CharNode *wapp_char_list_remove(CharList *list, u64 index) { - CharNode *output = NULL; - if (!list) { - goto RETURN_CHAR_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_char_list_pop_front(list); - goto RETURN_CHAR_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_char_list_pop_back(list); - goto RETURN_CHAR_LIST_REMOVE; - } - - output = wapp_char_list_get(list, index); - if (!output) { - goto RETURN_CHAR_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_CHAR_LIST_REMOVE: - return output; -} - -void wapp_char_list_empty(CharList *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_char_list_pop_back(list); - } -} - -C8Node *wapp_c8_list_get(const C8List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - C8Node *output = NULL; - C8Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_c8_list_push_front(C8List *list, C8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C8List node_list = c8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C8Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_c8_list_push_back(C8List *list, C8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C8List node_list = c8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C8Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_c8_list_insert(C8List *list, C8Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_c8_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_c8_list_push_back(list, node); - return; - } - - C8Node *dst_node = wapp_c8_list_get(list, index); - if (!dst_node) { - return; - } - - C8List node_list = c8_node_to_list(node); - - list->node_count += node_list.node_count; - - C8Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -C8Node *wapp_c8_list_pop_front(C8List *list) { - C8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C8_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (C8List){0}; - goto RETURN_C8_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_C8_LIST_POP_FRONT: - return output; -} - -C8Node *wapp_c8_list_pop_back(C8List *list) { - C8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C8_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (C8List){0}; - goto RETURN_C8_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_C8_LIST_POP_BACK: - return output; -} - -C8Node *wapp_c8_list_remove(C8List *list, u64 index) { - C8Node *output = NULL; - if (!list) { - goto RETURN_C8_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_c8_list_pop_front(list); - goto RETURN_C8_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_c8_list_pop_back(list); - goto RETURN_C8_LIST_REMOVE; - } - - output = wapp_c8_list_get(list, index); - if (!output) { - goto RETURN_C8_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_C8_LIST_REMOVE: - return output; -} - -void wapp_c8_list_empty(C8List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_c8_list_pop_back(list); - } -} - -C16Node *wapp_c16_list_get(const C16List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - C16Node *output = NULL; - C16Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_c16_list_push_front(C16List *list, C16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C16List node_list = c16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C16Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_c16_list_push_back(C16List *list, C16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C16List node_list = c16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C16Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_c16_list_insert(C16List *list, C16Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_c16_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_c16_list_push_back(list, node); - return; - } - - C16Node *dst_node = wapp_c16_list_get(list, index); - if (!dst_node) { - return; - } - - C16List node_list = c16_node_to_list(node); - - list->node_count += node_list.node_count; - - C16Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -C16Node *wapp_c16_list_pop_front(C16List *list) { - C16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C16_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (C16List){0}; - goto RETURN_C16_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_C16_LIST_POP_FRONT: - return output; -} - -C16Node *wapp_c16_list_pop_back(C16List *list) { - C16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C16_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (C16List){0}; - goto RETURN_C16_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_C16_LIST_POP_BACK: - return output; -} - -C16Node *wapp_c16_list_remove(C16List *list, u64 index) { - C16Node *output = NULL; - if (!list) { - goto RETURN_C16_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_c16_list_pop_front(list); - goto RETURN_C16_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_c16_list_pop_back(list); - goto RETURN_C16_LIST_REMOVE; - } - - output = wapp_c16_list_get(list, index); - if (!output) { - goto RETURN_C16_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_C16_LIST_REMOVE: - return output; -} - -void wapp_c16_list_empty(C16List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_c16_list_pop_back(list); - } -} - -C32Node *wapp_c32_list_get(const C32List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - C32Node *output = NULL; - C32Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_c32_list_push_front(C32List *list, C32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C32List node_list = c32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C32Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_c32_list_push_back(C32List *list, C32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - C32List node_list = c32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - C32Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_c32_list_insert(C32List *list, C32Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_c32_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_c32_list_push_back(list, node); - return; - } - - C32Node *dst_node = wapp_c32_list_get(list, index); - if (!dst_node) { - return; - } - - C32List node_list = c32_node_to_list(node); - - list->node_count += node_list.node_count; - - C32Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -C32Node *wapp_c32_list_pop_front(C32List *list) { - C32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C32_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (C32List){0}; - goto RETURN_C32_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_C32_LIST_POP_FRONT: - return output; -} - -C32Node *wapp_c32_list_pop_back(C32List *list) { - C32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_C32_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (C32List){0}; - goto RETURN_C32_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_C32_LIST_POP_BACK: - return output; -} - -C32Node *wapp_c32_list_remove(C32List *list, u64 index) { - C32Node *output = NULL; - if (!list) { - goto RETURN_C32_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_c32_list_pop_front(list); - goto RETURN_C32_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_c32_list_pop_back(list); - goto RETURN_C32_LIST_REMOVE; - } - - output = wapp_c32_list_get(list, index); - if (!output) { - goto RETURN_C32_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_C32_LIST_REMOVE: - return output; -} - -void wapp_c32_list_empty(C32List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_c32_list_pop_back(list); - } -} - -I8Node *wapp_i8_list_get(const I8List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - I8Node *output = NULL; - I8Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_i8_list_push_front(I8List *list, I8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I8List node_list = i8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I8Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_i8_list_push_back(I8List *list, I8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I8List node_list = i8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I8Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_i8_list_insert(I8List *list, I8Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_i8_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_i8_list_push_back(list, node); - return; - } - - I8Node *dst_node = wapp_i8_list_get(list, index); - if (!dst_node) { - return; - } - - I8List node_list = i8_node_to_list(node); - - list->node_count += node_list.node_count; - - I8Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -I8Node *wapp_i8_list_pop_front(I8List *list) { - I8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I8_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (I8List){0}; - goto RETURN_I8_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_I8_LIST_POP_FRONT: - return output; -} - -I8Node *wapp_i8_list_pop_back(I8List *list) { - I8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I8_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (I8List){0}; - goto RETURN_I8_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_I8_LIST_POP_BACK: - return output; -} - -I8Node *wapp_i8_list_remove(I8List *list, u64 index) { - I8Node *output = NULL; - if (!list) { - goto RETURN_I8_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_i8_list_pop_front(list); - goto RETURN_I8_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_i8_list_pop_back(list); - goto RETURN_I8_LIST_REMOVE; - } - - output = wapp_i8_list_get(list, index); - if (!output) { - goto RETURN_I8_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_I8_LIST_REMOVE: - return output; -} - -void wapp_i8_list_empty(I8List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_i8_list_pop_back(list); - } -} - -I16Node *wapp_i16_list_get(const I16List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - I16Node *output = NULL; - I16Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_i16_list_push_front(I16List *list, I16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I16List node_list = i16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I16Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_i16_list_push_back(I16List *list, I16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I16List node_list = i16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I16Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_i16_list_insert(I16List *list, I16Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_i16_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_i16_list_push_back(list, node); - return; - } - - I16Node *dst_node = wapp_i16_list_get(list, index); - if (!dst_node) { - return; - } - - I16List node_list = i16_node_to_list(node); - - list->node_count += node_list.node_count; - - I16Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -I16Node *wapp_i16_list_pop_front(I16List *list) { - I16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I16_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (I16List){0}; - goto RETURN_I16_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_I16_LIST_POP_FRONT: - return output; -} - -I16Node *wapp_i16_list_pop_back(I16List *list) { - I16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I16_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (I16List){0}; - goto RETURN_I16_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_I16_LIST_POP_BACK: - return output; -} - -I16Node *wapp_i16_list_remove(I16List *list, u64 index) { - I16Node *output = NULL; - if (!list) { - goto RETURN_I16_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_i16_list_pop_front(list); - goto RETURN_I16_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_i16_list_pop_back(list); - goto RETURN_I16_LIST_REMOVE; - } - - output = wapp_i16_list_get(list, index); - if (!output) { - goto RETURN_I16_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_I16_LIST_REMOVE: - return output; -} - -void wapp_i16_list_empty(I16List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_i16_list_pop_back(list); - } -} - -I32Node *wapp_i32_list_get(const I32List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - I32Node *output = NULL; - I32Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_i32_list_push_front(I32List *list, I32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I32List node_list = i32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I32Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_i32_list_push_back(I32List *list, I32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I32List node_list = i32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I32Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_i32_list_insert(I32List *list, I32Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_i32_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_i32_list_push_back(list, node); - return; - } - - I32Node *dst_node = wapp_i32_list_get(list, index); - if (!dst_node) { - return; - } - - I32List node_list = i32_node_to_list(node); - - list->node_count += node_list.node_count; - - I32Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -I32Node *wapp_i32_list_pop_front(I32List *list) { - I32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I32_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (I32List){0}; - goto RETURN_I32_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_I32_LIST_POP_FRONT: - return output; -} - -I32Node *wapp_i32_list_pop_back(I32List *list) { - I32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I32_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (I32List){0}; - goto RETURN_I32_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_I32_LIST_POP_BACK: - return output; -} - -I32Node *wapp_i32_list_remove(I32List *list, u64 index) { - I32Node *output = NULL; - if (!list) { - goto RETURN_I32_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_i32_list_pop_front(list); - goto RETURN_I32_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_i32_list_pop_back(list); - goto RETURN_I32_LIST_REMOVE; - } - - output = wapp_i32_list_get(list, index); - if (!output) { - goto RETURN_I32_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_I32_LIST_REMOVE: - return output; -} - -void wapp_i32_list_empty(I32List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_i32_list_pop_back(list); - } -} - -I64Node *wapp_i64_list_get(const I64List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - I64Node *output = NULL; - I64Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_i64_list_push_front(I64List *list, I64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I64List node_list = i64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I64Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_i64_list_push_back(I64List *list, I64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - I64List node_list = i64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - I64Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_i64_list_insert(I64List *list, I64Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_i64_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_i64_list_push_back(list, node); - return; - } - - I64Node *dst_node = wapp_i64_list_get(list, index); - if (!dst_node) { - return; - } - - I64List node_list = i64_node_to_list(node); - - list->node_count += node_list.node_count; - - I64Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -I64Node *wapp_i64_list_pop_front(I64List *list) { - I64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I64_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (I64List){0}; - goto RETURN_I64_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_I64_LIST_POP_FRONT: - return output; -} - -I64Node *wapp_i64_list_pop_back(I64List *list) { - I64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_I64_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (I64List){0}; - goto RETURN_I64_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_I64_LIST_POP_BACK: - return output; -} - -I64Node *wapp_i64_list_remove(I64List *list, u64 index) { - I64Node *output = NULL; - if (!list) { - goto RETURN_I64_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_i64_list_pop_front(list); - goto RETURN_I64_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_i64_list_pop_back(list); - goto RETURN_I64_LIST_REMOVE; - } - - output = wapp_i64_list_get(list, index); - if (!output) { - goto RETURN_I64_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_I64_LIST_REMOVE: - return output; -} - -void wapp_i64_list_empty(I64List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_i64_list_pop_back(list); - } -} - -U8Node *wapp_u8_list_get(const U8List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - U8Node *output = NULL; - U8Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_u8_list_push_front(U8List *list, U8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U8List node_list = u8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U8Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_u8_list_push_back(U8List *list, U8Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U8List node_list = u8_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U8Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_u8_list_insert(U8List *list, U8Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_u8_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_u8_list_push_back(list, node); - return; - } - - U8Node *dst_node = wapp_u8_list_get(list, index); - if (!dst_node) { - return; - } - - U8List node_list = u8_node_to_list(node); - - list->node_count += node_list.node_count; - - U8Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -U8Node *wapp_u8_list_pop_front(U8List *list) { - U8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U8_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (U8List){0}; - goto RETURN_U8_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_U8_LIST_POP_FRONT: - return output; -} - -U8Node *wapp_u8_list_pop_back(U8List *list) { - U8Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U8_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (U8List){0}; - goto RETURN_U8_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_U8_LIST_POP_BACK: - return output; -} - -U8Node *wapp_u8_list_remove(U8List *list, u64 index) { - U8Node *output = NULL; - if (!list) { - goto RETURN_U8_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_u8_list_pop_front(list); - goto RETURN_U8_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_u8_list_pop_back(list); - goto RETURN_U8_LIST_REMOVE; - } - - output = wapp_u8_list_get(list, index); - if (!output) { - goto RETURN_U8_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_U8_LIST_REMOVE: - return output; -} - -void wapp_u8_list_empty(U8List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_u8_list_pop_back(list); - } -} - -U16Node *wapp_u16_list_get(const U16List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - U16Node *output = NULL; - U16Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_u16_list_push_front(U16List *list, U16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U16List node_list = u16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U16Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_u16_list_push_back(U16List *list, U16Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U16List node_list = u16_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U16Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_u16_list_insert(U16List *list, U16Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_u16_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_u16_list_push_back(list, node); - return; - } - - U16Node *dst_node = wapp_u16_list_get(list, index); - if (!dst_node) { - return; - } - - U16List node_list = u16_node_to_list(node); - - list->node_count += node_list.node_count; - - U16Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -U16Node *wapp_u16_list_pop_front(U16List *list) { - U16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U16_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (U16List){0}; - goto RETURN_U16_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_U16_LIST_POP_FRONT: - return output; -} - -U16Node *wapp_u16_list_pop_back(U16List *list) { - U16Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U16_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (U16List){0}; - goto RETURN_U16_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_U16_LIST_POP_BACK: - return output; -} - -U16Node *wapp_u16_list_remove(U16List *list, u64 index) { - U16Node *output = NULL; - if (!list) { - goto RETURN_U16_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_u16_list_pop_front(list); - goto RETURN_U16_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_u16_list_pop_back(list); - goto RETURN_U16_LIST_REMOVE; - } - - output = wapp_u16_list_get(list, index); - if (!output) { - goto RETURN_U16_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_U16_LIST_REMOVE: - return output; -} - -void wapp_u16_list_empty(U16List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_u16_list_pop_back(list); - } -} - -U32Node *wapp_u32_list_get(const U32List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - U32Node *output = NULL; - U32Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_u32_list_push_front(U32List *list, U32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U32List node_list = u32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U32Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_u32_list_push_back(U32List *list, U32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U32List node_list = u32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U32Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_u32_list_insert(U32List *list, U32Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_u32_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_u32_list_push_back(list, node); - return; - } - - U32Node *dst_node = wapp_u32_list_get(list, index); - if (!dst_node) { - return; - } - - U32List node_list = u32_node_to_list(node); - - list->node_count += node_list.node_count; - - U32Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -U32Node *wapp_u32_list_pop_front(U32List *list) { - U32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U32_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (U32List){0}; - goto RETURN_U32_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_U32_LIST_POP_FRONT: - return output; -} - -U32Node *wapp_u32_list_pop_back(U32List *list) { - U32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U32_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (U32List){0}; - goto RETURN_U32_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_U32_LIST_POP_BACK: - return output; -} - -U32Node *wapp_u32_list_remove(U32List *list, u64 index) { - U32Node *output = NULL; - if (!list) { - goto RETURN_U32_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_u32_list_pop_front(list); - goto RETURN_U32_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_u32_list_pop_back(list); - goto RETURN_U32_LIST_REMOVE; - } - - output = wapp_u32_list_get(list, index); - if (!output) { - goto RETURN_U32_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_U32_LIST_REMOVE: - return output; -} - -void wapp_u32_list_empty(U32List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_u32_list_pop_back(list); - } -} - -U64Node *wapp_u64_list_get(const U64List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - U64Node *output = NULL; - U64Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_u64_list_push_front(U64List *list, U64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U64List node_list = u64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U64Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_u64_list_push_back(U64List *list, U64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - U64List node_list = u64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - U64Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_u64_list_insert(U64List *list, U64Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_u64_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_u64_list_push_back(list, node); - return; - } - - U64Node *dst_node = wapp_u64_list_get(list, index); - if (!dst_node) { - return; - } - - U64List node_list = u64_node_to_list(node); - - list->node_count += node_list.node_count; - - U64Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -U64Node *wapp_u64_list_pop_front(U64List *list) { - U64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U64_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (U64List){0}; - goto RETURN_U64_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_U64_LIST_POP_FRONT: - return output; -} - -U64Node *wapp_u64_list_pop_back(U64List *list) { - U64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_U64_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (U64List){0}; - goto RETURN_U64_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_U64_LIST_POP_BACK: - return output; -} - -U64Node *wapp_u64_list_remove(U64List *list, u64 index) { - U64Node *output = NULL; - if (!list) { - goto RETURN_U64_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_u64_list_pop_front(list); - goto RETURN_U64_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_u64_list_pop_back(list); - goto RETURN_U64_LIST_REMOVE; - } - - output = wapp_u64_list_get(list, index); - if (!output) { - goto RETURN_U64_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_U64_LIST_REMOVE: - return output; -} - -void wapp_u64_list_empty(U64List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_u64_list_pop_back(list); - } -} - -F32Node *wapp_f32_list_get(const F32List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - F32Node *output = NULL; - F32Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_f32_list_push_front(F32List *list, F32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F32List node_list = f32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F32Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_f32_list_push_back(F32List *list, F32Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F32List node_list = f32_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F32Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_f32_list_insert(F32List *list, F32Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_f32_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_f32_list_push_back(list, node); - return; - } - - F32Node *dst_node = wapp_f32_list_get(list, index); - if (!dst_node) { - return; - } - - F32List node_list = f32_node_to_list(node); - - list->node_count += node_list.node_count; - - F32Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -F32Node *wapp_f32_list_pop_front(F32List *list) { - F32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F32_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (F32List){0}; - goto RETURN_F32_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_F32_LIST_POP_FRONT: - return output; -} - -F32Node *wapp_f32_list_pop_back(F32List *list) { - F32Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F32_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (F32List){0}; - goto RETURN_F32_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_F32_LIST_POP_BACK: - return output; -} - -F32Node *wapp_f32_list_remove(F32List *list, u64 index) { - F32Node *output = NULL; - if (!list) { - goto RETURN_F32_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_f32_list_pop_front(list); - goto RETURN_F32_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_f32_list_pop_back(list); - goto RETURN_F32_LIST_REMOVE; - } - - output = wapp_f32_list_get(list, index); - if (!output) { - goto RETURN_F32_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_F32_LIST_REMOVE: - return output; -} - -void wapp_f32_list_empty(F32List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_f32_list_pop_back(list); - } -} - -F64Node *wapp_f64_list_get(const F64List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - F64Node *output = NULL; - F64Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_f64_list_push_front(F64List *list, F64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F64List node_list = f64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F64Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_f64_list_push_back(F64List *list, F64Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F64List node_list = f64_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F64Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_f64_list_insert(F64List *list, F64Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_f64_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_f64_list_push_back(list, node); - return; - } - - F64Node *dst_node = wapp_f64_list_get(list, index); - if (!dst_node) { - return; - } - - F64List node_list = f64_node_to_list(node); - - list->node_count += node_list.node_count; - - F64Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -F64Node *wapp_f64_list_pop_front(F64List *list) { - F64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F64_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (F64List){0}; - goto RETURN_F64_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_F64_LIST_POP_FRONT: - return output; -} - -F64Node *wapp_f64_list_pop_back(F64List *list) { - F64Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F64_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (F64List){0}; - goto RETURN_F64_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_F64_LIST_POP_BACK: - return output; -} - -F64Node *wapp_f64_list_remove(F64List *list, u64 index) { - F64Node *output = NULL; - if (!list) { - goto RETURN_F64_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_f64_list_pop_front(list); - goto RETURN_F64_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_f64_list_pop_back(list); - goto RETURN_F64_LIST_REMOVE; - } - - output = wapp_f64_list_get(list, index); - if (!output) { - goto RETURN_F64_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_F64_LIST_REMOVE: - return output; -} - -void wapp_f64_list_empty(F64List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_f64_list_pop_back(list); - } -} - -F128Node *wapp_f128_list_get(const F128List *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - F128Node *output = NULL; - F128Node *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_f128_list_push_front(F128List *list, F128Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F128List node_list = f128_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F128Node *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_f128_list_push_back(F128List *list, F128Node *node) { - if (!list || !node || !(node->item)) { - return; - } - - F128List node_list = f128_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - F128Node *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_f128_list_insert(F128List *list, F128Node *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_f128_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_f128_list_push_back(list, node); - return; - } - - F128Node *dst_node = wapp_f128_list_get(list, index); - if (!dst_node) { - return; - } - - F128List node_list = f128_node_to_list(node); - - list->node_count += node_list.node_count; - - F128Node *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -F128Node *wapp_f128_list_pop_front(F128List *list) { - F128Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F128_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (F128List){0}; - goto RETURN_F128_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_F128_LIST_POP_FRONT: - return output; -} - -F128Node *wapp_f128_list_pop_back(F128List *list) { - F128Node *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_F128_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (F128List){0}; - goto RETURN_F128_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_F128_LIST_POP_BACK: - return output; -} - -F128Node *wapp_f128_list_remove(F128List *list, u64 index) { - F128Node *output = NULL; - if (!list) { - goto RETURN_F128_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_f128_list_pop_front(list); - goto RETURN_F128_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_f128_list_pop_back(list); - goto RETURN_F128_LIST_REMOVE; - } - - output = wapp_f128_list_get(list, index); - if (!output) { - goto RETURN_F128_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_F128_LIST_REMOVE: - return output; -} - -void wapp_f128_list_empty(F128List *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_f128_list_pop_back(list); - } -} - -IptrNode *wapp_iptr_list_get(const IptrList *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - IptrNode *output = NULL; - IptrNode *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_iptr_list_push_front(IptrList *list, IptrNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - IptrList node_list = iptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - IptrNode *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_iptr_list_push_back(IptrList *list, IptrNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - IptrList node_list = iptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - IptrNode *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_iptr_list_insert(IptrList *list, IptrNode *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_iptr_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_iptr_list_push_back(list, node); - return; - } - - IptrNode *dst_node = wapp_iptr_list_get(list, index); - if (!dst_node) { - return; - } - - IptrList node_list = iptr_node_to_list(node); - - list->node_count += node_list.node_count; - - IptrNode *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -IptrNode *wapp_iptr_list_pop_front(IptrList *list) { - IptrNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_IPTR_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (IptrList){0}; - goto RETURN_IPTR_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_IPTR_LIST_POP_FRONT: - return output; -} - -IptrNode *wapp_iptr_list_pop_back(IptrList *list) { - IptrNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_IPTR_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (IptrList){0}; - goto RETURN_IPTR_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_IPTR_LIST_POP_BACK: - return output; -} - -IptrNode *wapp_iptr_list_remove(IptrList *list, u64 index) { - IptrNode *output = NULL; - if (!list) { - goto RETURN_IPTR_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_iptr_list_pop_front(list); - goto RETURN_IPTR_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_iptr_list_pop_back(list); - goto RETURN_IPTR_LIST_REMOVE; - } - - output = wapp_iptr_list_get(list, index); - if (!output) { - goto RETURN_IPTR_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_IPTR_LIST_REMOVE: - return output; -} - -void wapp_iptr_list_empty(IptrList *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_iptr_list_pop_back(list); - } -} - -UptrNode *wapp_uptr_list_get(const UptrList *list, u64 index) { - if (index >= list->node_count) { - return NULL; - } - - UptrNode *output = NULL; - UptrNode *current = list->first; - for (u64 i = 1; i <= index; ++i) { - current = current->next; - } - - output = current; - - return output; -} - -void wapp_uptr_list_push_front(UptrList *list, UptrNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - UptrList node_list = uptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - UptrNode *first = list->first; - if (first) { - first->prev = node_list.last; - } - - list->first = node_list.first; - node_list.last->next = first; -} - -void wapp_uptr_list_push_back(UptrList *list, UptrNode *node) { - if (!list || !node || !(node->item)) { - return; - } - - UptrList node_list = uptr_node_to_list(node); - - if (list->node_count == 0) { - *list = node_list; - return; - } - - list->node_count += node_list.node_count; - - UptrNode *last = list->last; - if (last) { - last->next = node_list.first; - } - - list->last = node_list.last; - node_list.first->prev = last; -} - -void wapp_uptr_list_insert(UptrList *list, UptrNode *node, u64 index) { - if (!list || !node || !(node->item)) { - return; - } - - if (index == 0) { - wapp_uptr_list_push_front(list, node); - return; - } else if (index == list->node_count) { - wapp_uptr_list_push_back(list, node); - return; - } - - UptrNode *dst_node = wapp_uptr_list_get(list, index); - if (!dst_node) { - return; - } - - UptrList node_list = uptr_node_to_list(node); - - list->node_count += node_list.node_count; - - UptrNode *prev = dst_node->prev; - - dst_node->prev = node_list.last; - prev->next = node_list.first; - - node_list.first->prev = prev; - node_list.last->next = dst_node; -} - -UptrNode *wapp_uptr_list_pop_front(UptrList *list) { - UptrNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_UPTR_LIST_POP_FRONT; - } - - output = list->first; - - if (list->node_count == 1) { - *list = (UptrList){0}; - goto RETURN_UPTR_LIST_POP_FRONT; - } - - --(list->node_count); - list->first = output->next; - - output->prev = output->next = NULL; - -RETURN_UPTR_LIST_POP_FRONT: - return output; -} - -UptrNode *wapp_uptr_list_pop_back(UptrList *list) { - UptrNode *output = NULL; - - if (!list || list->node_count == 0) { - goto RETURN_UPTR_LIST_POP_BACK; - } - - output = list->last; - - if (list->node_count == 1) { - *list = (UptrList){0}; - goto RETURN_UPTR_LIST_POP_BACK; - } - - --(list->node_count); - list->last = output->prev; - - output->prev = output->next = NULL; - -RETURN_UPTR_LIST_POP_BACK: - return output; -} - -UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index) { - UptrNode *output = NULL; - if (!list) { - goto RETURN_UPTR_LIST_REMOVE; - } - - if (index == 0) { - output = wapp_uptr_list_pop_front(list); - goto RETURN_UPTR_LIST_REMOVE; - } else if (index == list->node_count) { - output = wapp_uptr_list_pop_back(list); - goto RETURN_UPTR_LIST_REMOVE; - } - - output = wapp_uptr_list_get(list, index); - if (!output) { - goto RETURN_UPTR_LIST_REMOVE; - } - - output->prev->next = output->next; - output->next->prev = output->prev; - - --(list->node_count); - - output->prev = output->next = NULL; - -RETURN_UPTR_LIST_REMOVE: - return output; -} - -void wapp_uptr_list_empty(UptrList *list) { - if (!list) { - return; - } - - u64 count = list->node_count; - for (u64 i = 0; i < count; ++i) { - wapp_uptr_list_pop_back(list); - } -} - -internal Str8List str8_node_to_list(Str8Node *node) { - Str8List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal VoidPList void_ptr_node_to_list(VoidPNode *node) { - VoidPList output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal BoolList bool_node_to_list(BoolNode *node) { - BoolList output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal CharList char_node_to_list(CharNode *node) { - CharList output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal C8List c8_node_to_list(C8Node *node) { - C8List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal C16List c16_node_to_list(C16Node *node) { - C16List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal C32List c32_node_to_list(C32Node *node) { - C32List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal I8List i8_node_to_list(I8Node *node) { - I8List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal I16List i16_node_to_list(I16Node *node) { - I16List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal I32List i32_node_to_list(I32Node *node) { - I32List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal I64List i64_node_to_list(I64Node *node) { - I64List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal U8List u8_node_to_list(U8Node *node) { - U8List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal U16List u16_node_to_list(U16Node *node) { - U16List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal U32List u32_node_to_list(U32Node *node) { - U32List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal U64List u64_node_to_list(U64Node *node) { - U64List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal F32List f32_node_to_list(F32Node *node) { - F32List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal F64List f64_node_to_list(F64Node *node) { - F64List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal F128List f128_node_to_list(F128Node *node) { - F128List output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal IptrList iptr_node_to_list(IptrNode *node) { - IptrList output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - -internal UptrList uptr_node_to_list(UptrNode *node) { - UptrList output = {.first = node, .last = node, .node_count = 1}; - - while (output.first->prev != NULL) { - output.first = output.first->prev; - ++(output.node_count); - } - - while (output.last->next != NULL) { - output.last = output.last->next; - ++(output.node_count); - } - - return output; -} - +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#include "./dbl_list.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include +#include + +internal Str8List str8_node_to_list(Str8Node *node); +internal VoidPList void_ptr_node_to_list(VoidPNode *node); +internal BoolList bool_node_to_list(BoolNode *node); +internal CharList char_node_to_list(CharNode *node); +internal C8List c8_node_to_list(C8Node *node); +internal C16List c16_node_to_list(C16Node *node); +internal C32List c32_node_to_list(C32Node *node); +internal I8List i8_node_to_list(I8Node *node); +internal I16List i16_node_to_list(I16Node *node); +internal I32List i32_node_to_list(I32Node *node); +internal I64List i64_node_to_list(I64Node *node); +internal U8List u8_node_to_list(U8Node *node); +internal U16List u16_node_to_list(U16Node *node); +internal U32List u32_node_to_list(U32Node *node); +internal U64List u64_node_to_list(U64Node *node); +internal F32List f32_node_to_list(F32Node *node); +internal F64List f64_node_to_list(F64Node *node); +internal F128List f128_node_to_list(F128Node *node); +internal IptrList iptr_node_to_list(IptrNode *node); +internal UptrList uptr_node_to_list(UptrNode *node); + +Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + Str8Node *output = NULL; + Str8Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + Str8List node_list = str8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + Str8Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + Str8List node_list = str8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + Str8Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_str8_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_str8_list_push_back(list, node); + return; + } + + Str8Node *dst_node = wapp_str8_list_get(list, index); + if (!dst_node) { + return; + } + + Str8List node_list = str8_node_to_list(node); + + list->node_count += node_list.node_count; + + Str8Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +Str8Node *wapp_str8_list_pop_front(Str8List *list) { + Str8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_STR8_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (Str8List){0}; + goto RETURN_STR8_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_STR8_LIST_POP_FRONT: + return output; +} + +Str8Node *wapp_str8_list_pop_back(Str8List *list) { + Str8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_STR8_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (Str8List){0}; + goto RETURN_STR8_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_STR8_LIST_POP_BACK: + return output; +} + +Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { + Str8Node *output = NULL; + if (!list) { + goto RETURN_STR8_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_str8_list_pop_front(list); + goto RETURN_STR8_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_str8_list_pop_back(list); + goto RETURN_STR8_LIST_REMOVE; + } + + output = wapp_str8_list_get(list, index); + if (!output) { + goto RETURN_STR8_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_STR8_LIST_REMOVE: + return output; +} + +void wapp_str8_list_empty(Str8List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_str8_list_pop_back(list); + } +} + +VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + VoidPNode *output = NULL; + VoidPNode *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + VoidPList node_list = void_ptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + VoidPNode *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + VoidPList node_list = void_ptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + VoidPNode *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_void_ptr_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_void_ptr_list_push_back(list, node); + return; + } + + VoidPNode *dst_node = wapp_void_ptr_list_get(list, index); + if (!dst_node) { + return; + } + + VoidPList node_list = void_ptr_node_to_list(node); + + list->node_count += node_list.node_count; + + VoidPNode *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list) { + VoidPNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_VOID_PTR_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (VoidPList){0}; + goto RETURN_VOID_PTR_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_VOID_PTR_LIST_POP_FRONT: + return output; +} + +VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list) { + VoidPNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_VOID_PTR_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (VoidPList){0}; + goto RETURN_VOID_PTR_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_VOID_PTR_LIST_POP_BACK: + return output; +} + +VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index) { + VoidPNode *output = NULL; + if (!list) { + goto RETURN_VOID_PTR_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_void_ptr_list_pop_front(list); + goto RETURN_VOID_PTR_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_void_ptr_list_pop_back(list); + goto RETURN_VOID_PTR_LIST_REMOVE; + } + + output = wapp_void_ptr_list_get(list, index); + if (!output) { + goto RETURN_VOID_PTR_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_VOID_PTR_LIST_REMOVE: + return output; +} + +void wapp_void_ptr_list_empty(VoidPList *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_void_ptr_list_pop_back(list); + } +} + +BoolNode *wapp_bool_list_get(const BoolList *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + BoolNode *output = NULL; + BoolNode *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_bool_list_push_front(BoolList *list, BoolNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + BoolList node_list = bool_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + BoolNode *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_bool_list_push_back(BoolList *list, BoolNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + BoolList node_list = bool_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + BoolNode *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_bool_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_bool_list_push_back(list, node); + return; + } + + BoolNode *dst_node = wapp_bool_list_get(list, index); + if (!dst_node) { + return; + } + + BoolList node_list = bool_node_to_list(node); + + list->node_count += node_list.node_count; + + BoolNode *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +BoolNode *wapp_bool_list_pop_front(BoolList *list) { + BoolNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_BOOL_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (BoolList){0}; + goto RETURN_BOOL_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_BOOL_LIST_POP_FRONT: + return output; +} + +BoolNode *wapp_bool_list_pop_back(BoolList *list) { + BoolNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_BOOL_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (BoolList){0}; + goto RETURN_BOOL_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_BOOL_LIST_POP_BACK: + return output; +} + +BoolNode *wapp_bool_list_remove(BoolList *list, u64 index) { + BoolNode *output = NULL; + if (!list) { + goto RETURN_BOOL_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_bool_list_pop_front(list); + goto RETURN_BOOL_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_bool_list_pop_back(list); + goto RETURN_BOOL_LIST_REMOVE; + } + + output = wapp_bool_list_get(list, index); + if (!output) { + goto RETURN_BOOL_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_BOOL_LIST_REMOVE: + return output; +} + +void wapp_bool_list_empty(BoolList *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_bool_list_pop_back(list); + } +} + +CharNode *wapp_char_list_get(const CharList *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + CharNode *output = NULL; + CharNode *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_char_list_push_front(CharList *list, CharNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + CharList node_list = char_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + CharNode *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_char_list_push_back(CharList *list, CharNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + CharList node_list = char_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + CharNode *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_char_list_insert(CharList *list, CharNode *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_char_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_char_list_push_back(list, node); + return; + } + + CharNode *dst_node = wapp_char_list_get(list, index); + if (!dst_node) { + return; + } + + CharList node_list = char_node_to_list(node); + + list->node_count += node_list.node_count; + + CharNode *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +CharNode *wapp_char_list_pop_front(CharList *list) { + CharNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_CHAR_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (CharList){0}; + goto RETURN_CHAR_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_CHAR_LIST_POP_FRONT: + return output; +} + +CharNode *wapp_char_list_pop_back(CharList *list) { + CharNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_CHAR_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (CharList){0}; + goto RETURN_CHAR_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_CHAR_LIST_POP_BACK: + return output; +} + +CharNode *wapp_char_list_remove(CharList *list, u64 index) { + CharNode *output = NULL; + if (!list) { + goto RETURN_CHAR_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_char_list_pop_front(list); + goto RETURN_CHAR_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_char_list_pop_back(list); + goto RETURN_CHAR_LIST_REMOVE; + } + + output = wapp_char_list_get(list, index); + if (!output) { + goto RETURN_CHAR_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_CHAR_LIST_REMOVE: + return output; +} + +void wapp_char_list_empty(CharList *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_char_list_pop_back(list); + } +} + +C8Node *wapp_c8_list_get(const C8List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + C8Node *output = NULL; + C8Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_c8_list_push_front(C8List *list, C8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C8List node_list = c8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C8Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_c8_list_push_back(C8List *list, C8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C8List node_list = c8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C8Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_c8_list_insert(C8List *list, C8Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_c8_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_c8_list_push_back(list, node); + return; + } + + C8Node *dst_node = wapp_c8_list_get(list, index); + if (!dst_node) { + return; + } + + C8List node_list = c8_node_to_list(node); + + list->node_count += node_list.node_count; + + C8Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +C8Node *wapp_c8_list_pop_front(C8List *list) { + C8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C8_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (C8List){0}; + goto RETURN_C8_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_C8_LIST_POP_FRONT: + return output; +} + +C8Node *wapp_c8_list_pop_back(C8List *list) { + C8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C8_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (C8List){0}; + goto RETURN_C8_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_C8_LIST_POP_BACK: + return output; +} + +C8Node *wapp_c8_list_remove(C8List *list, u64 index) { + C8Node *output = NULL; + if (!list) { + goto RETURN_C8_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_c8_list_pop_front(list); + goto RETURN_C8_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_c8_list_pop_back(list); + goto RETURN_C8_LIST_REMOVE; + } + + output = wapp_c8_list_get(list, index); + if (!output) { + goto RETURN_C8_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_C8_LIST_REMOVE: + return output; +} + +void wapp_c8_list_empty(C8List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_c8_list_pop_back(list); + } +} + +C16Node *wapp_c16_list_get(const C16List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + C16Node *output = NULL; + C16Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_c16_list_push_front(C16List *list, C16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C16List node_list = c16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C16Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_c16_list_push_back(C16List *list, C16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C16List node_list = c16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C16Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_c16_list_insert(C16List *list, C16Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_c16_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_c16_list_push_back(list, node); + return; + } + + C16Node *dst_node = wapp_c16_list_get(list, index); + if (!dst_node) { + return; + } + + C16List node_list = c16_node_to_list(node); + + list->node_count += node_list.node_count; + + C16Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +C16Node *wapp_c16_list_pop_front(C16List *list) { + C16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C16_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (C16List){0}; + goto RETURN_C16_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_C16_LIST_POP_FRONT: + return output; +} + +C16Node *wapp_c16_list_pop_back(C16List *list) { + C16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C16_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (C16List){0}; + goto RETURN_C16_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_C16_LIST_POP_BACK: + return output; +} + +C16Node *wapp_c16_list_remove(C16List *list, u64 index) { + C16Node *output = NULL; + if (!list) { + goto RETURN_C16_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_c16_list_pop_front(list); + goto RETURN_C16_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_c16_list_pop_back(list); + goto RETURN_C16_LIST_REMOVE; + } + + output = wapp_c16_list_get(list, index); + if (!output) { + goto RETURN_C16_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_C16_LIST_REMOVE: + return output; +} + +void wapp_c16_list_empty(C16List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_c16_list_pop_back(list); + } +} + +C32Node *wapp_c32_list_get(const C32List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + C32Node *output = NULL; + C32Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_c32_list_push_front(C32List *list, C32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C32List node_list = c32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C32Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_c32_list_push_back(C32List *list, C32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + C32List node_list = c32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + C32Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_c32_list_insert(C32List *list, C32Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_c32_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_c32_list_push_back(list, node); + return; + } + + C32Node *dst_node = wapp_c32_list_get(list, index); + if (!dst_node) { + return; + } + + C32List node_list = c32_node_to_list(node); + + list->node_count += node_list.node_count; + + C32Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +C32Node *wapp_c32_list_pop_front(C32List *list) { + C32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C32_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (C32List){0}; + goto RETURN_C32_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_C32_LIST_POP_FRONT: + return output; +} + +C32Node *wapp_c32_list_pop_back(C32List *list) { + C32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_C32_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (C32List){0}; + goto RETURN_C32_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_C32_LIST_POP_BACK: + return output; +} + +C32Node *wapp_c32_list_remove(C32List *list, u64 index) { + C32Node *output = NULL; + if (!list) { + goto RETURN_C32_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_c32_list_pop_front(list); + goto RETURN_C32_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_c32_list_pop_back(list); + goto RETURN_C32_LIST_REMOVE; + } + + output = wapp_c32_list_get(list, index); + if (!output) { + goto RETURN_C32_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_C32_LIST_REMOVE: + return output; +} + +void wapp_c32_list_empty(C32List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_c32_list_pop_back(list); + } +} + +I8Node *wapp_i8_list_get(const I8List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + I8Node *output = NULL; + I8Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_i8_list_push_front(I8List *list, I8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I8List node_list = i8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I8Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_i8_list_push_back(I8List *list, I8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I8List node_list = i8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I8Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_i8_list_insert(I8List *list, I8Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_i8_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_i8_list_push_back(list, node); + return; + } + + I8Node *dst_node = wapp_i8_list_get(list, index); + if (!dst_node) { + return; + } + + I8List node_list = i8_node_to_list(node); + + list->node_count += node_list.node_count; + + I8Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +I8Node *wapp_i8_list_pop_front(I8List *list) { + I8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I8_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (I8List){0}; + goto RETURN_I8_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_I8_LIST_POP_FRONT: + return output; +} + +I8Node *wapp_i8_list_pop_back(I8List *list) { + I8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I8_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (I8List){0}; + goto RETURN_I8_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_I8_LIST_POP_BACK: + return output; +} + +I8Node *wapp_i8_list_remove(I8List *list, u64 index) { + I8Node *output = NULL; + if (!list) { + goto RETURN_I8_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_i8_list_pop_front(list); + goto RETURN_I8_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_i8_list_pop_back(list); + goto RETURN_I8_LIST_REMOVE; + } + + output = wapp_i8_list_get(list, index); + if (!output) { + goto RETURN_I8_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_I8_LIST_REMOVE: + return output; +} + +void wapp_i8_list_empty(I8List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_i8_list_pop_back(list); + } +} + +I16Node *wapp_i16_list_get(const I16List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + I16Node *output = NULL; + I16Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_i16_list_push_front(I16List *list, I16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I16List node_list = i16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I16Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_i16_list_push_back(I16List *list, I16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I16List node_list = i16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I16Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_i16_list_insert(I16List *list, I16Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_i16_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_i16_list_push_back(list, node); + return; + } + + I16Node *dst_node = wapp_i16_list_get(list, index); + if (!dst_node) { + return; + } + + I16List node_list = i16_node_to_list(node); + + list->node_count += node_list.node_count; + + I16Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +I16Node *wapp_i16_list_pop_front(I16List *list) { + I16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I16_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (I16List){0}; + goto RETURN_I16_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_I16_LIST_POP_FRONT: + return output; +} + +I16Node *wapp_i16_list_pop_back(I16List *list) { + I16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I16_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (I16List){0}; + goto RETURN_I16_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_I16_LIST_POP_BACK: + return output; +} + +I16Node *wapp_i16_list_remove(I16List *list, u64 index) { + I16Node *output = NULL; + if (!list) { + goto RETURN_I16_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_i16_list_pop_front(list); + goto RETURN_I16_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_i16_list_pop_back(list); + goto RETURN_I16_LIST_REMOVE; + } + + output = wapp_i16_list_get(list, index); + if (!output) { + goto RETURN_I16_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_I16_LIST_REMOVE: + return output; +} + +void wapp_i16_list_empty(I16List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_i16_list_pop_back(list); + } +} + +I32Node *wapp_i32_list_get(const I32List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + I32Node *output = NULL; + I32Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_i32_list_push_front(I32List *list, I32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I32List node_list = i32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I32Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_i32_list_push_back(I32List *list, I32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I32List node_list = i32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I32Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_i32_list_insert(I32List *list, I32Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_i32_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_i32_list_push_back(list, node); + return; + } + + I32Node *dst_node = wapp_i32_list_get(list, index); + if (!dst_node) { + return; + } + + I32List node_list = i32_node_to_list(node); + + list->node_count += node_list.node_count; + + I32Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +I32Node *wapp_i32_list_pop_front(I32List *list) { + I32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I32_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (I32List){0}; + goto RETURN_I32_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_I32_LIST_POP_FRONT: + return output; +} + +I32Node *wapp_i32_list_pop_back(I32List *list) { + I32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I32_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (I32List){0}; + goto RETURN_I32_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_I32_LIST_POP_BACK: + return output; +} + +I32Node *wapp_i32_list_remove(I32List *list, u64 index) { + I32Node *output = NULL; + if (!list) { + goto RETURN_I32_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_i32_list_pop_front(list); + goto RETURN_I32_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_i32_list_pop_back(list); + goto RETURN_I32_LIST_REMOVE; + } + + output = wapp_i32_list_get(list, index); + if (!output) { + goto RETURN_I32_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_I32_LIST_REMOVE: + return output; +} + +void wapp_i32_list_empty(I32List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_i32_list_pop_back(list); + } +} + +I64Node *wapp_i64_list_get(const I64List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + I64Node *output = NULL; + I64Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_i64_list_push_front(I64List *list, I64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I64List node_list = i64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I64Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_i64_list_push_back(I64List *list, I64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + I64List node_list = i64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + I64Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_i64_list_insert(I64List *list, I64Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_i64_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_i64_list_push_back(list, node); + return; + } + + I64Node *dst_node = wapp_i64_list_get(list, index); + if (!dst_node) { + return; + } + + I64List node_list = i64_node_to_list(node); + + list->node_count += node_list.node_count; + + I64Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +I64Node *wapp_i64_list_pop_front(I64List *list) { + I64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I64_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (I64List){0}; + goto RETURN_I64_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_I64_LIST_POP_FRONT: + return output; +} + +I64Node *wapp_i64_list_pop_back(I64List *list) { + I64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_I64_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (I64List){0}; + goto RETURN_I64_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_I64_LIST_POP_BACK: + return output; +} + +I64Node *wapp_i64_list_remove(I64List *list, u64 index) { + I64Node *output = NULL; + if (!list) { + goto RETURN_I64_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_i64_list_pop_front(list); + goto RETURN_I64_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_i64_list_pop_back(list); + goto RETURN_I64_LIST_REMOVE; + } + + output = wapp_i64_list_get(list, index); + if (!output) { + goto RETURN_I64_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_I64_LIST_REMOVE: + return output; +} + +void wapp_i64_list_empty(I64List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_i64_list_pop_back(list); + } +} + +U8Node *wapp_u8_list_get(const U8List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + U8Node *output = NULL; + U8Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_u8_list_push_front(U8List *list, U8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U8List node_list = u8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U8Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_u8_list_push_back(U8List *list, U8Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U8List node_list = u8_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U8Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_u8_list_insert(U8List *list, U8Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_u8_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_u8_list_push_back(list, node); + return; + } + + U8Node *dst_node = wapp_u8_list_get(list, index); + if (!dst_node) { + return; + } + + U8List node_list = u8_node_to_list(node); + + list->node_count += node_list.node_count; + + U8Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +U8Node *wapp_u8_list_pop_front(U8List *list) { + U8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U8_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (U8List){0}; + goto RETURN_U8_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_U8_LIST_POP_FRONT: + return output; +} + +U8Node *wapp_u8_list_pop_back(U8List *list) { + U8Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U8_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (U8List){0}; + goto RETURN_U8_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_U8_LIST_POP_BACK: + return output; +} + +U8Node *wapp_u8_list_remove(U8List *list, u64 index) { + U8Node *output = NULL; + if (!list) { + goto RETURN_U8_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_u8_list_pop_front(list); + goto RETURN_U8_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_u8_list_pop_back(list); + goto RETURN_U8_LIST_REMOVE; + } + + output = wapp_u8_list_get(list, index); + if (!output) { + goto RETURN_U8_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_U8_LIST_REMOVE: + return output; +} + +void wapp_u8_list_empty(U8List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_u8_list_pop_back(list); + } +} + +U16Node *wapp_u16_list_get(const U16List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + U16Node *output = NULL; + U16Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_u16_list_push_front(U16List *list, U16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U16List node_list = u16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U16Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_u16_list_push_back(U16List *list, U16Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U16List node_list = u16_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U16Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_u16_list_insert(U16List *list, U16Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_u16_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_u16_list_push_back(list, node); + return; + } + + U16Node *dst_node = wapp_u16_list_get(list, index); + if (!dst_node) { + return; + } + + U16List node_list = u16_node_to_list(node); + + list->node_count += node_list.node_count; + + U16Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +U16Node *wapp_u16_list_pop_front(U16List *list) { + U16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U16_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (U16List){0}; + goto RETURN_U16_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_U16_LIST_POP_FRONT: + return output; +} + +U16Node *wapp_u16_list_pop_back(U16List *list) { + U16Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U16_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (U16List){0}; + goto RETURN_U16_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_U16_LIST_POP_BACK: + return output; +} + +U16Node *wapp_u16_list_remove(U16List *list, u64 index) { + U16Node *output = NULL; + if (!list) { + goto RETURN_U16_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_u16_list_pop_front(list); + goto RETURN_U16_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_u16_list_pop_back(list); + goto RETURN_U16_LIST_REMOVE; + } + + output = wapp_u16_list_get(list, index); + if (!output) { + goto RETURN_U16_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_U16_LIST_REMOVE: + return output; +} + +void wapp_u16_list_empty(U16List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_u16_list_pop_back(list); + } +} + +U32Node *wapp_u32_list_get(const U32List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + U32Node *output = NULL; + U32Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_u32_list_push_front(U32List *list, U32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U32List node_list = u32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U32Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_u32_list_push_back(U32List *list, U32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U32List node_list = u32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U32Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_u32_list_insert(U32List *list, U32Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_u32_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_u32_list_push_back(list, node); + return; + } + + U32Node *dst_node = wapp_u32_list_get(list, index); + if (!dst_node) { + return; + } + + U32List node_list = u32_node_to_list(node); + + list->node_count += node_list.node_count; + + U32Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +U32Node *wapp_u32_list_pop_front(U32List *list) { + U32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U32_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (U32List){0}; + goto RETURN_U32_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_U32_LIST_POP_FRONT: + return output; +} + +U32Node *wapp_u32_list_pop_back(U32List *list) { + U32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U32_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (U32List){0}; + goto RETURN_U32_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_U32_LIST_POP_BACK: + return output; +} + +U32Node *wapp_u32_list_remove(U32List *list, u64 index) { + U32Node *output = NULL; + if (!list) { + goto RETURN_U32_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_u32_list_pop_front(list); + goto RETURN_U32_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_u32_list_pop_back(list); + goto RETURN_U32_LIST_REMOVE; + } + + output = wapp_u32_list_get(list, index); + if (!output) { + goto RETURN_U32_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_U32_LIST_REMOVE: + return output; +} + +void wapp_u32_list_empty(U32List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_u32_list_pop_back(list); + } +} + +U64Node *wapp_u64_list_get(const U64List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + U64Node *output = NULL; + U64Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_u64_list_push_front(U64List *list, U64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U64List node_list = u64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U64Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_u64_list_push_back(U64List *list, U64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + U64List node_list = u64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + U64Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_u64_list_insert(U64List *list, U64Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_u64_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_u64_list_push_back(list, node); + return; + } + + U64Node *dst_node = wapp_u64_list_get(list, index); + if (!dst_node) { + return; + } + + U64List node_list = u64_node_to_list(node); + + list->node_count += node_list.node_count; + + U64Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +U64Node *wapp_u64_list_pop_front(U64List *list) { + U64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U64_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (U64List){0}; + goto RETURN_U64_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_U64_LIST_POP_FRONT: + return output; +} + +U64Node *wapp_u64_list_pop_back(U64List *list) { + U64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_U64_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (U64List){0}; + goto RETURN_U64_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_U64_LIST_POP_BACK: + return output; +} + +U64Node *wapp_u64_list_remove(U64List *list, u64 index) { + U64Node *output = NULL; + if (!list) { + goto RETURN_U64_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_u64_list_pop_front(list); + goto RETURN_U64_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_u64_list_pop_back(list); + goto RETURN_U64_LIST_REMOVE; + } + + output = wapp_u64_list_get(list, index); + if (!output) { + goto RETURN_U64_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_U64_LIST_REMOVE: + return output; +} + +void wapp_u64_list_empty(U64List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_u64_list_pop_back(list); + } +} + +F32Node *wapp_f32_list_get(const F32List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + F32Node *output = NULL; + F32Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_f32_list_push_front(F32List *list, F32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F32List node_list = f32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F32Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_f32_list_push_back(F32List *list, F32Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F32List node_list = f32_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F32Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_f32_list_insert(F32List *list, F32Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_f32_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_f32_list_push_back(list, node); + return; + } + + F32Node *dst_node = wapp_f32_list_get(list, index); + if (!dst_node) { + return; + } + + F32List node_list = f32_node_to_list(node); + + list->node_count += node_list.node_count; + + F32Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +F32Node *wapp_f32_list_pop_front(F32List *list) { + F32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F32_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (F32List){0}; + goto RETURN_F32_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_F32_LIST_POP_FRONT: + return output; +} + +F32Node *wapp_f32_list_pop_back(F32List *list) { + F32Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F32_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (F32List){0}; + goto RETURN_F32_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_F32_LIST_POP_BACK: + return output; +} + +F32Node *wapp_f32_list_remove(F32List *list, u64 index) { + F32Node *output = NULL; + if (!list) { + goto RETURN_F32_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_f32_list_pop_front(list); + goto RETURN_F32_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_f32_list_pop_back(list); + goto RETURN_F32_LIST_REMOVE; + } + + output = wapp_f32_list_get(list, index); + if (!output) { + goto RETURN_F32_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_F32_LIST_REMOVE: + return output; +} + +void wapp_f32_list_empty(F32List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_f32_list_pop_back(list); + } +} + +F64Node *wapp_f64_list_get(const F64List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + F64Node *output = NULL; + F64Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_f64_list_push_front(F64List *list, F64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F64List node_list = f64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F64Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_f64_list_push_back(F64List *list, F64Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F64List node_list = f64_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F64Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_f64_list_insert(F64List *list, F64Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_f64_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_f64_list_push_back(list, node); + return; + } + + F64Node *dst_node = wapp_f64_list_get(list, index); + if (!dst_node) { + return; + } + + F64List node_list = f64_node_to_list(node); + + list->node_count += node_list.node_count; + + F64Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +F64Node *wapp_f64_list_pop_front(F64List *list) { + F64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F64_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (F64List){0}; + goto RETURN_F64_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_F64_LIST_POP_FRONT: + return output; +} + +F64Node *wapp_f64_list_pop_back(F64List *list) { + F64Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F64_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (F64List){0}; + goto RETURN_F64_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_F64_LIST_POP_BACK: + return output; +} + +F64Node *wapp_f64_list_remove(F64List *list, u64 index) { + F64Node *output = NULL; + if (!list) { + goto RETURN_F64_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_f64_list_pop_front(list); + goto RETURN_F64_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_f64_list_pop_back(list); + goto RETURN_F64_LIST_REMOVE; + } + + output = wapp_f64_list_get(list, index); + if (!output) { + goto RETURN_F64_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_F64_LIST_REMOVE: + return output; +} + +void wapp_f64_list_empty(F64List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_f64_list_pop_back(list); + } +} + +F128Node *wapp_f128_list_get(const F128List *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + F128Node *output = NULL; + F128Node *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_f128_list_push_front(F128List *list, F128Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F128List node_list = f128_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F128Node *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_f128_list_push_back(F128List *list, F128Node *node) { + if (!list || !node || !(node->item)) { + return; + } + + F128List node_list = f128_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + F128Node *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_f128_list_insert(F128List *list, F128Node *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_f128_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_f128_list_push_back(list, node); + return; + } + + F128Node *dst_node = wapp_f128_list_get(list, index); + if (!dst_node) { + return; + } + + F128List node_list = f128_node_to_list(node); + + list->node_count += node_list.node_count; + + F128Node *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +F128Node *wapp_f128_list_pop_front(F128List *list) { + F128Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F128_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (F128List){0}; + goto RETURN_F128_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_F128_LIST_POP_FRONT: + return output; +} + +F128Node *wapp_f128_list_pop_back(F128List *list) { + F128Node *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_F128_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (F128List){0}; + goto RETURN_F128_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_F128_LIST_POP_BACK: + return output; +} + +F128Node *wapp_f128_list_remove(F128List *list, u64 index) { + F128Node *output = NULL; + if (!list) { + goto RETURN_F128_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_f128_list_pop_front(list); + goto RETURN_F128_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_f128_list_pop_back(list); + goto RETURN_F128_LIST_REMOVE; + } + + output = wapp_f128_list_get(list, index); + if (!output) { + goto RETURN_F128_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_F128_LIST_REMOVE: + return output; +} + +void wapp_f128_list_empty(F128List *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_f128_list_pop_back(list); + } +} + +IptrNode *wapp_iptr_list_get(const IptrList *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + IptrNode *output = NULL; + IptrNode *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_iptr_list_push_front(IptrList *list, IptrNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + IptrList node_list = iptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + IptrNode *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_iptr_list_push_back(IptrList *list, IptrNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + IptrList node_list = iptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + IptrNode *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_iptr_list_insert(IptrList *list, IptrNode *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_iptr_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_iptr_list_push_back(list, node); + return; + } + + IptrNode *dst_node = wapp_iptr_list_get(list, index); + if (!dst_node) { + return; + } + + IptrList node_list = iptr_node_to_list(node); + + list->node_count += node_list.node_count; + + IptrNode *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +IptrNode *wapp_iptr_list_pop_front(IptrList *list) { + IptrNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_IPTR_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (IptrList){0}; + goto RETURN_IPTR_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_IPTR_LIST_POP_FRONT: + return output; +} + +IptrNode *wapp_iptr_list_pop_back(IptrList *list) { + IptrNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_IPTR_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (IptrList){0}; + goto RETURN_IPTR_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_IPTR_LIST_POP_BACK: + return output; +} + +IptrNode *wapp_iptr_list_remove(IptrList *list, u64 index) { + IptrNode *output = NULL; + if (!list) { + goto RETURN_IPTR_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_iptr_list_pop_front(list); + goto RETURN_IPTR_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_iptr_list_pop_back(list); + goto RETURN_IPTR_LIST_REMOVE; + } + + output = wapp_iptr_list_get(list, index); + if (!output) { + goto RETURN_IPTR_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_IPTR_LIST_REMOVE: + return output; +} + +void wapp_iptr_list_empty(IptrList *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_iptr_list_pop_back(list); + } +} + +UptrNode *wapp_uptr_list_get(const UptrList *list, u64 index) { + if (index >= list->node_count) { + return NULL; + } + + UptrNode *output = NULL; + UptrNode *current = list->first; + for (u64 i = 1; i <= index; ++i) { + current = current->next; + } + + output = current; + + return output; +} + +void wapp_uptr_list_push_front(UptrList *list, UptrNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + UptrList node_list = uptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + UptrNode *first = list->first; + if (first) { + first->prev = node_list.last; + } + + list->first = node_list.first; + node_list.last->next = first; +} + +void wapp_uptr_list_push_back(UptrList *list, UptrNode *node) { + if (!list || !node || !(node->item)) { + return; + } + + UptrList node_list = uptr_node_to_list(node); + + if (list->node_count == 0) { + *list = node_list; + return; + } + + list->node_count += node_list.node_count; + + UptrNode *last = list->last; + if (last) { + last->next = node_list.first; + } + + list->last = node_list.last; + node_list.first->prev = last; +} + +void wapp_uptr_list_insert(UptrList *list, UptrNode *node, u64 index) { + if (!list || !node || !(node->item)) { + return; + } + + if (index == 0) { + wapp_uptr_list_push_front(list, node); + return; + } else if (index == list->node_count) { + wapp_uptr_list_push_back(list, node); + return; + } + + UptrNode *dst_node = wapp_uptr_list_get(list, index); + if (!dst_node) { + return; + } + + UptrList node_list = uptr_node_to_list(node); + + list->node_count += node_list.node_count; + + UptrNode *prev = dst_node->prev; + + dst_node->prev = node_list.last; + prev->next = node_list.first; + + node_list.first->prev = prev; + node_list.last->next = dst_node; +} + +UptrNode *wapp_uptr_list_pop_front(UptrList *list) { + UptrNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_UPTR_LIST_POP_FRONT; + } + + output = list->first; + + if (list->node_count == 1) { + *list = (UptrList){0}; + goto RETURN_UPTR_LIST_POP_FRONT; + } + + --(list->node_count); + list->first = output->next; + + output->prev = output->next = NULL; + +RETURN_UPTR_LIST_POP_FRONT: + return output; +} + +UptrNode *wapp_uptr_list_pop_back(UptrList *list) { + UptrNode *output = NULL; + + if (!list || list->node_count == 0) { + goto RETURN_UPTR_LIST_POP_BACK; + } + + output = list->last; + + if (list->node_count == 1) { + *list = (UptrList){0}; + goto RETURN_UPTR_LIST_POP_BACK; + } + + --(list->node_count); + list->last = output->prev; + + output->prev = output->next = NULL; + +RETURN_UPTR_LIST_POP_BACK: + return output; +} + +UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index) { + UptrNode *output = NULL; + if (!list) { + goto RETURN_UPTR_LIST_REMOVE; + } + + if (index == 0) { + output = wapp_uptr_list_pop_front(list); + goto RETURN_UPTR_LIST_REMOVE; + } else if (index == list->node_count) { + output = wapp_uptr_list_pop_back(list); + goto RETURN_UPTR_LIST_REMOVE; + } + + output = wapp_uptr_list_get(list, index); + if (!output) { + goto RETURN_UPTR_LIST_REMOVE; + } + + output->prev->next = output->next; + output->next->prev = output->prev; + + --(list->node_count); + + output->prev = output->next = NULL; + +RETURN_UPTR_LIST_REMOVE: + return output; +} + +void wapp_uptr_list_empty(UptrList *list) { + if (!list) { + return; + } + + u64 count = list->node_count; + for (u64 i = 0; i < count; ++i) { + wapp_uptr_list_pop_back(list); + } +} + +internal Str8List str8_node_to_list(Str8Node *node) { + Str8List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal VoidPList void_ptr_node_to_list(VoidPNode *node) { + VoidPList output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal BoolList bool_node_to_list(BoolNode *node) { + BoolList output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal CharList char_node_to_list(CharNode *node) { + CharList output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal C8List c8_node_to_list(C8Node *node) { + C8List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal C16List c16_node_to_list(C16Node *node) { + C16List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal C32List c32_node_to_list(C32Node *node) { + C32List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal I8List i8_node_to_list(I8Node *node) { + I8List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal I16List i16_node_to_list(I16Node *node) { + I16List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal I32List i32_node_to_list(I32Node *node) { + I32List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal I64List i64_node_to_list(I64Node *node) { + I64List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal U8List u8_node_to_list(U8Node *node) { + U8List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal U16List u16_node_to_list(U16Node *node) { + U16List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal U32List u32_node_to_list(U32Node *node) { + U32List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal U64List u64_node_to_list(U64Node *node) { + U64List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal F32List f32_node_to_list(F32Node *node) { + F32List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal F64List f64_node_to_list(F64Node *node) { + F64List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal F128List f128_node_to_list(F128Node *node) { + F128List output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal IptrList iptr_node_to_list(IptrNode *node) { + IptrList output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + +internal UptrList uptr_node_to_list(UptrNode *node) { + UptrList output = {.first = node, .last = node, .node_count = 1}; + + while (output.first->prev != NULL) { + output.first = output.first->prev; + ++(output.node_count); + } + + while (output.last->next != NULL) { + output.last = output.last->next; + ++(output.node_count); + } + + return output; +} + diff --git a/src/primitives/dbl_list/dbl_list.h b/src/primitives/dbl_list/dbl_list.h index 63807af..a7a9f24 100644 --- a/src/primitives/dbl_list/dbl_list.h +++ b/src/primitives/dbl_list/dbl_list.h @@ -1,484 +1,484 @@ -/** - * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN - */ - -#ifndef DBL_LIST_H -#define DBL_LIST_H - -#include "../../common/aliases/aliases.h" -#include "../../common/platform/platform.h" -#include - -#ifdef WAPP_PLATFORM_CPP -BEGIN_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR}) -#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR}) -#define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.item = ITEM_PTR}) -#define wapp_char_list_node(ITEM_PTR) ((CharNode){.item = ITEM_PTR}) -#define wapp_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR}) -#define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR}) -#define wapp_c32_list_node(ITEM_PTR) ((C32Node){.item = ITEM_PTR}) -#define wapp_i8_list_node(ITEM_PTR) ((I8Node){.item = ITEM_PTR}) -#define wapp_i16_list_node(ITEM_PTR) ((I16Node){.item = ITEM_PTR}) -#define wapp_i32_list_node(ITEM_PTR) ((I32Node){.item = ITEM_PTR}) -#define wapp_i64_list_node(ITEM_PTR) ((I64Node){.item = ITEM_PTR}) -#define wapp_u8_list_node(ITEM_PTR) ((U8Node){.item = ITEM_PTR}) -#define wapp_u16_list_node(ITEM_PTR) ((U16Node){.item = ITEM_PTR}) -#define wapp_u32_list_node(ITEM_PTR) ((U32Node){.item = ITEM_PTR}) -#define wapp_u64_list_node(ITEM_PTR) ((U64Node){.item = ITEM_PTR}) -#define wapp_f32_list_node(ITEM_PTR) ((F32Node){.item = ITEM_PTR}) -#define wapp_f64_list_node(ITEM_PTR) ((F64Node){.item = ITEM_PTR}) -#define wapp_f128_list_node(ITEM_PTR) ((F128Node){.item = ITEM_PTR}) -#define wapp_iptr_list_node(ITEM_PTR) ((IptrNode){.item = ITEM_PTR}) -#define wapp_uptr_list_node(ITEM_PTR) ((UptrNode){.item = ITEM_PTR}) - -typedef struct str8 Str8; - -typedef struct Str8Node Str8Node; -struct Str8Node { - Str8 *item; - Str8Node *prev; - Str8Node *next; -}; - -typedef struct Str8List Str8List; -struct Str8List { - Str8Node *first; - Str8Node *last; - u64 node_count; -}; - -typedef struct VoidPNode VoidPNode; -struct VoidPNode { - void * *item; - VoidPNode *prev; - VoidPNode *next; -}; - -typedef struct VoidPList VoidPList; -struct VoidPList { - VoidPNode *first; - VoidPNode *last; - u64 node_count; -}; - -typedef struct BoolNode BoolNode; -struct BoolNode { - bool *item; - BoolNode *prev; - BoolNode *next; -}; - -typedef struct BoolList BoolList; -struct BoolList { - BoolNode *first; - BoolNode *last; - u64 node_count; -}; - -typedef struct CharNode CharNode; -struct CharNode { - char *item; - CharNode *prev; - CharNode *next; -}; - -typedef struct CharList CharList; -struct CharList { - CharNode *first; - CharNode *last; - u64 node_count; -}; - -typedef struct C8Node C8Node; -struct C8Node { - c8 *item; - C8Node *prev; - C8Node *next; -}; - -typedef struct C8List C8List; -struct C8List { - C8Node *first; - C8Node *last; - u64 node_count; -}; - -typedef struct C16Node C16Node; -struct C16Node { - c16 *item; - C16Node *prev; - C16Node *next; -}; - -typedef struct C16List C16List; -struct C16List { - C16Node *first; - C16Node *last; - u64 node_count; -}; - -typedef struct C32Node C32Node; -struct C32Node { - c32 *item; - C32Node *prev; - C32Node *next; -}; - -typedef struct C32List C32List; -struct C32List { - C32Node *first; - C32Node *last; - u64 node_count; -}; - -typedef struct I8Node I8Node; -struct I8Node { - i8 *item; - I8Node *prev; - I8Node *next; -}; - -typedef struct I8List I8List; -struct I8List { - I8Node *first; - I8Node *last; - u64 node_count; -}; - -typedef struct I16Node I16Node; -struct I16Node { - i16 *item; - I16Node *prev; - I16Node *next; -}; - -typedef struct I16List I16List; -struct I16List { - I16Node *first; - I16Node *last; - u64 node_count; -}; - -typedef struct I32Node I32Node; -struct I32Node { - i32 *item; - I32Node *prev; - I32Node *next; -}; - -typedef struct I32List I32List; -struct I32List { - I32Node *first; - I32Node *last; - u64 node_count; -}; - -typedef struct I64Node I64Node; -struct I64Node { - i64 *item; - I64Node *prev; - I64Node *next; -}; - -typedef struct I64List I64List; -struct I64List { - I64Node *first; - I64Node *last; - u64 node_count; -}; - -typedef struct U8Node U8Node; -struct U8Node { - u8 *item; - U8Node *prev; - U8Node *next; -}; - -typedef struct U8List U8List; -struct U8List { - U8Node *first; - U8Node *last; - u64 node_count; -}; - -typedef struct U16Node U16Node; -struct U16Node { - u16 *item; - U16Node *prev; - U16Node *next; -}; - -typedef struct U16List U16List; -struct U16List { - U16Node *first; - U16Node *last; - u64 node_count; -}; - -typedef struct U32Node U32Node; -struct U32Node { - u32 *item; - U32Node *prev; - U32Node *next; -}; - -typedef struct U32List U32List; -struct U32List { - U32Node *first; - U32Node *last; - u64 node_count; -}; - -typedef struct U64Node U64Node; -struct U64Node { - u64 *item; - U64Node *prev; - U64Node *next; -}; - -typedef struct U64List U64List; -struct U64List { - U64Node *first; - U64Node *last; - u64 node_count; -}; - -typedef struct F32Node F32Node; -struct F32Node { - f32 *item; - F32Node *prev; - F32Node *next; -}; - -typedef struct F32List F32List; -struct F32List { - F32Node *first; - F32Node *last; - u64 node_count; -}; - -typedef struct F64Node F64Node; -struct F64Node { - f64 *item; - F64Node *prev; - F64Node *next; -}; - -typedef struct F64List F64List; -struct F64List { - F64Node *first; - F64Node *last; - u64 node_count; -}; - -typedef struct F128Node F128Node; -struct F128Node { - f128 *item; - F128Node *prev; - F128Node *next; -}; - -typedef struct F128List F128List; -struct F128List { - F128Node *first; - F128Node *last; - u64 node_count; -}; - -typedef struct IptrNode IptrNode; -struct IptrNode { - iptr *item; - IptrNode *prev; - IptrNode *next; -}; - -typedef struct IptrList IptrList; -struct IptrList { - IptrNode *first; - IptrNode *last; - u64 node_count; -}; - -typedef struct UptrNode UptrNode; -struct UptrNode { - uptr *item; - UptrNode *prev; - UptrNode *next; -}; - -typedef struct UptrList UptrList; -struct UptrList { - UptrNode *first; - UptrNode *last; - u64 node_count; -}; - -Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); -void wapp_str8_list_push_front(Str8List *list, Str8Node *node); -void wapp_str8_list_push_back(Str8List *list, Str8Node *node); -void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index); -Str8Node *wapp_str8_list_pop_front(Str8List *list); -Str8Node *wapp_str8_list_pop_back(Str8List *list); -Str8Node *wapp_str8_list_remove(Str8List *list, u64 index); -void wapp_str8_list_empty(Str8List *list); -VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index); -void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node); -void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node); -void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index); -VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list); -VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list); -VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index); -void wapp_void_ptr_list_empty(VoidPList *list); -BoolNode *wapp_bool_list_get(const BoolList *list, u64 index); -void wapp_bool_list_push_front(BoolList *list, BoolNode *node); -void wapp_bool_list_push_back(BoolList *list, BoolNode *node); -void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index); -BoolNode *wapp_bool_list_pop_front(BoolList *list); -BoolNode *wapp_bool_list_pop_back(BoolList *list); -BoolNode *wapp_bool_list_remove(BoolList *list, u64 index); -void wapp_bool_list_empty(BoolList *list); -CharNode *wapp_char_list_get(const CharList *list, u64 index); -void wapp_char_list_push_front(CharList *list, CharNode *node); -void wapp_char_list_push_back(CharList *list, CharNode *node); -void wapp_char_list_insert(CharList *list, CharNode *node, u64 index); -CharNode *wapp_char_list_pop_front(CharList *list); -CharNode *wapp_char_list_pop_back(CharList *list); -CharNode *wapp_char_list_remove(CharList *list, u64 index); -void wapp_char_list_empty(CharList *list); -C8Node *wapp_c8_list_get(const C8List *list, u64 index); -void wapp_c8_list_push_front(C8List *list, C8Node *node); -void wapp_c8_list_push_back(C8List *list, C8Node *node); -void wapp_c8_list_insert(C8List *list, C8Node *node, u64 index); -C8Node *wapp_c8_list_pop_front(C8List *list); -C8Node *wapp_c8_list_pop_back(C8List *list); -C8Node *wapp_c8_list_remove(C8List *list, u64 index); -void wapp_c8_list_empty(C8List *list); -C16Node *wapp_c16_list_get(const C16List *list, u64 index); -void wapp_c16_list_push_front(C16List *list, C16Node *node); -void wapp_c16_list_push_back(C16List *list, C16Node *node); -void wapp_c16_list_insert(C16List *list, C16Node *node, u64 index); -C16Node *wapp_c16_list_pop_front(C16List *list); -C16Node *wapp_c16_list_pop_back(C16List *list); -C16Node *wapp_c16_list_remove(C16List *list, u64 index); -void wapp_c16_list_empty(C16List *list); -C32Node *wapp_c32_list_get(const C32List *list, u64 index); -void wapp_c32_list_push_front(C32List *list, C32Node *node); -void wapp_c32_list_push_back(C32List *list, C32Node *node); -void wapp_c32_list_insert(C32List *list, C32Node *node, u64 index); -C32Node *wapp_c32_list_pop_front(C32List *list); -C32Node *wapp_c32_list_pop_back(C32List *list); -C32Node *wapp_c32_list_remove(C32List *list, u64 index); -void wapp_c32_list_empty(C32List *list); -I8Node *wapp_i8_list_get(const I8List *list, u64 index); -void wapp_i8_list_push_front(I8List *list, I8Node *node); -void wapp_i8_list_push_back(I8List *list, I8Node *node); -void wapp_i8_list_insert(I8List *list, I8Node *node, u64 index); -I8Node *wapp_i8_list_pop_front(I8List *list); -I8Node *wapp_i8_list_pop_back(I8List *list); -I8Node *wapp_i8_list_remove(I8List *list, u64 index); -void wapp_i8_list_empty(I8List *list); -I16Node *wapp_i16_list_get(const I16List *list, u64 index); -void wapp_i16_list_push_front(I16List *list, I16Node *node); -void wapp_i16_list_push_back(I16List *list, I16Node *node); -void wapp_i16_list_insert(I16List *list, I16Node *node, u64 index); -I16Node *wapp_i16_list_pop_front(I16List *list); -I16Node *wapp_i16_list_pop_back(I16List *list); -I16Node *wapp_i16_list_remove(I16List *list, u64 index); -void wapp_i16_list_empty(I16List *list); -I32Node *wapp_i32_list_get(const I32List *list, u64 index); -void wapp_i32_list_push_front(I32List *list, I32Node *node); -void wapp_i32_list_push_back(I32List *list, I32Node *node); -void wapp_i32_list_insert(I32List *list, I32Node *node, u64 index); -I32Node *wapp_i32_list_pop_front(I32List *list); -I32Node *wapp_i32_list_pop_back(I32List *list); -I32Node *wapp_i32_list_remove(I32List *list, u64 index); -void wapp_i32_list_empty(I32List *list); -I64Node *wapp_i64_list_get(const I64List *list, u64 index); -void wapp_i64_list_push_front(I64List *list, I64Node *node); -void wapp_i64_list_push_back(I64List *list, I64Node *node); -void wapp_i64_list_insert(I64List *list, I64Node *node, u64 index); -I64Node *wapp_i64_list_pop_front(I64List *list); -I64Node *wapp_i64_list_pop_back(I64List *list); -I64Node *wapp_i64_list_remove(I64List *list, u64 index); -void wapp_i64_list_empty(I64List *list); -U8Node *wapp_u8_list_get(const U8List *list, u64 index); -void wapp_u8_list_push_front(U8List *list, U8Node *node); -void wapp_u8_list_push_back(U8List *list, U8Node *node); -void wapp_u8_list_insert(U8List *list, U8Node *node, u64 index); -U8Node *wapp_u8_list_pop_front(U8List *list); -U8Node *wapp_u8_list_pop_back(U8List *list); -U8Node *wapp_u8_list_remove(U8List *list, u64 index); -void wapp_u8_list_empty(U8List *list); -U16Node *wapp_u16_list_get(const U16List *list, u64 index); -void wapp_u16_list_push_front(U16List *list, U16Node *node); -void wapp_u16_list_push_back(U16List *list, U16Node *node); -void wapp_u16_list_insert(U16List *list, U16Node *node, u64 index); -U16Node *wapp_u16_list_pop_front(U16List *list); -U16Node *wapp_u16_list_pop_back(U16List *list); -U16Node *wapp_u16_list_remove(U16List *list, u64 index); -void wapp_u16_list_empty(U16List *list); -U32Node *wapp_u32_list_get(const U32List *list, u64 index); -void wapp_u32_list_push_front(U32List *list, U32Node *node); -void wapp_u32_list_push_back(U32List *list, U32Node *node); -void wapp_u32_list_insert(U32List *list, U32Node *node, u64 index); -U32Node *wapp_u32_list_pop_front(U32List *list); -U32Node *wapp_u32_list_pop_back(U32List *list); -U32Node *wapp_u32_list_remove(U32List *list, u64 index); -void wapp_u32_list_empty(U32List *list); -U64Node *wapp_u64_list_get(const U64List *list, u64 index); -void wapp_u64_list_push_front(U64List *list, U64Node *node); -void wapp_u64_list_push_back(U64List *list, U64Node *node); -void wapp_u64_list_insert(U64List *list, U64Node *node, u64 index); -U64Node *wapp_u64_list_pop_front(U64List *list); -U64Node *wapp_u64_list_pop_back(U64List *list); -U64Node *wapp_u64_list_remove(U64List *list, u64 index); -void wapp_u64_list_empty(U64List *list); -F32Node *wapp_f32_list_get(const F32List *list, u64 index); -void wapp_f32_list_push_front(F32List *list, F32Node *node); -void wapp_f32_list_push_back(F32List *list, F32Node *node); -void wapp_f32_list_insert(F32List *list, F32Node *node, u64 index); -F32Node *wapp_f32_list_pop_front(F32List *list); -F32Node *wapp_f32_list_pop_back(F32List *list); -F32Node *wapp_f32_list_remove(F32List *list, u64 index); -void wapp_f32_list_empty(F32List *list); -F64Node *wapp_f64_list_get(const F64List *list, u64 index); -void wapp_f64_list_push_front(F64List *list, F64Node *node); -void wapp_f64_list_push_back(F64List *list, F64Node *node); -void wapp_f64_list_insert(F64List *list, F64Node *node, u64 index); -F64Node *wapp_f64_list_pop_front(F64List *list); -F64Node *wapp_f64_list_pop_back(F64List *list); -F64Node *wapp_f64_list_remove(F64List *list, u64 index); -void wapp_f64_list_empty(F64List *list); -F128Node *wapp_f128_list_get(const F128List *list, u64 index); -void wapp_f128_list_push_front(F128List *list, F128Node *node); -void wapp_f128_list_push_back(F128List *list, F128Node *node); -void wapp_f128_list_insert(F128List *list, F128Node *node, u64 index); -F128Node *wapp_f128_list_pop_front(F128List *list); -F128Node *wapp_f128_list_pop_back(F128List *list); -F128Node *wapp_f128_list_remove(F128List *list, u64 index); -void wapp_f128_list_empty(F128List *list); -IptrNode *wapp_iptr_list_get(const IptrList *list, u64 index); -void wapp_iptr_list_push_front(IptrList *list, IptrNode *node); -void wapp_iptr_list_push_back(IptrList *list, IptrNode *node); -void wapp_iptr_list_insert(IptrList *list, IptrNode *node, u64 index); -IptrNode *wapp_iptr_list_pop_front(IptrList *list); -IptrNode *wapp_iptr_list_pop_back(IptrList *list); -IptrNode *wapp_iptr_list_remove(IptrList *list, u64 index); -void wapp_iptr_list_empty(IptrList *list); -UptrNode *wapp_uptr_list_get(const UptrList *list, u64 index); -void wapp_uptr_list_push_front(UptrList *list, UptrNode *node); -void wapp_uptr_list_push_back(UptrList *list, UptrNode *node); -void wapp_uptr_list_insert(UptrList *list, UptrNode *node, u64 index); -UptrNode *wapp_uptr_list_pop_front(UptrList *list); -UptrNode *wapp_uptr_list_pop_back(UptrList *list); -UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index); -void wapp_uptr_list_empty(UptrList *list); - -#ifdef WAPP_PLATFORM_CPP -END_C_LINKAGE -#endif // !WAPP_PLATFORM_CPP - -#endif // !DBL_LIST_H +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#ifndef DBL_LIST_H +#define DBL_LIST_H + +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include + +#ifdef WAPP_PLATFORM_CPP +BEGIN_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR}) +#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR}) +#define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.item = ITEM_PTR}) +#define wapp_char_list_node(ITEM_PTR) ((CharNode){.item = ITEM_PTR}) +#define wapp_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR}) +#define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR}) +#define wapp_c32_list_node(ITEM_PTR) ((C32Node){.item = ITEM_PTR}) +#define wapp_i8_list_node(ITEM_PTR) ((I8Node){.item = ITEM_PTR}) +#define wapp_i16_list_node(ITEM_PTR) ((I16Node){.item = ITEM_PTR}) +#define wapp_i32_list_node(ITEM_PTR) ((I32Node){.item = ITEM_PTR}) +#define wapp_i64_list_node(ITEM_PTR) ((I64Node){.item = ITEM_PTR}) +#define wapp_u8_list_node(ITEM_PTR) ((U8Node){.item = ITEM_PTR}) +#define wapp_u16_list_node(ITEM_PTR) ((U16Node){.item = ITEM_PTR}) +#define wapp_u32_list_node(ITEM_PTR) ((U32Node){.item = ITEM_PTR}) +#define wapp_u64_list_node(ITEM_PTR) ((U64Node){.item = ITEM_PTR}) +#define wapp_f32_list_node(ITEM_PTR) ((F32Node){.item = ITEM_PTR}) +#define wapp_f64_list_node(ITEM_PTR) ((F64Node){.item = ITEM_PTR}) +#define wapp_f128_list_node(ITEM_PTR) ((F128Node){.item = ITEM_PTR}) +#define wapp_iptr_list_node(ITEM_PTR) ((IptrNode){.item = ITEM_PTR}) +#define wapp_uptr_list_node(ITEM_PTR) ((UptrNode){.item = ITEM_PTR}) + +typedef struct str8 Str8; + +typedef struct Str8Node Str8Node; +struct Str8Node { + Str8 *item; + Str8Node *prev; + Str8Node *next; +}; + +typedef struct Str8List Str8List; +struct Str8List { + Str8Node *first; + Str8Node *last; + u64 node_count; +}; + +typedef struct VoidPNode VoidPNode; +struct VoidPNode { + void * *item; + VoidPNode *prev; + VoidPNode *next; +}; + +typedef struct VoidPList VoidPList; +struct VoidPList { + VoidPNode *first; + VoidPNode *last; + u64 node_count; +}; + +typedef struct BoolNode BoolNode; +struct BoolNode { + bool *item; + BoolNode *prev; + BoolNode *next; +}; + +typedef struct BoolList BoolList; +struct BoolList { + BoolNode *first; + BoolNode *last; + u64 node_count; +}; + +typedef struct CharNode CharNode; +struct CharNode { + char *item; + CharNode *prev; + CharNode *next; +}; + +typedef struct CharList CharList; +struct CharList { + CharNode *first; + CharNode *last; + u64 node_count; +}; + +typedef struct C8Node C8Node; +struct C8Node { + c8 *item; + C8Node *prev; + C8Node *next; +}; + +typedef struct C8List C8List; +struct C8List { + C8Node *first; + C8Node *last; + u64 node_count; +}; + +typedef struct C16Node C16Node; +struct C16Node { + c16 *item; + C16Node *prev; + C16Node *next; +}; + +typedef struct C16List C16List; +struct C16List { + C16Node *first; + C16Node *last; + u64 node_count; +}; + +typedef struct C32Node C32Node; +struct C32Node { + c32 *item; + C32Node *prev; + C32Node *next; +}; + +typedef struct C32List C32List; +struct C32List { + C32Node *first; + C32Node *last; + u64 node_count; +}; + +typedef struct I8Node I8Node; +struct I8Node { + i8 *item; + I8Node *prev; + I8Node *next; +}; + +typedef struct I8List I8List; +struct I8List { + I8Node *first; + I8Node *last; + u64 node_count; +}; + +typedef struct I16Node I16Node; +struct I16Node { + i16 *item; + I16Node *prev; + I16Node *next; +}; + +typedef struct I16List I16List; +struct I16List { + I16Node *first; + I16Node *last; + u64 node_count; +}; + +typedef struct I32Node I32Node; +struct I32Node { + i32 *item; + I32Node *prev; + I32Node *next; +}; + +typedef struct I32List I32List; +struct I32List { + I32Node *first; + I32Node *last; + u64 node_count; +}; + +typedef struct I64Node I64Node; +struct I64Node { + i64 *item; + I64Node *prev; + I64Node *next; +}; + +typedef struct I64List I64List; +struct I64List { + I64Node *first; + I64Node *last; + u64 node_count; +}; + +typedef struct U8Node U8Node; +struct U8Node { + u8 *item; + U8Node *prev; + U8Node *next; +}; + +typedef struct U8List U8List; +struct U8List { + U8Node *first; + U8Node *last; + u64 node_count; +}; + +typedef struct U16Node U16Node; +struct U16Node { + u16 *item; + U16Node *prev; + U16Node *next; +}; + +typedef struct U16List U16List; +struct U16List { + U16Node *first; + U16Node *last; + u64 node_count; +}; + +typedef struct U32Node U32Node; +struct U32Node { + u32 *item; + U32Node *prev; + U32Node *next; +}; + +typedef struct U32List U32List; +struct U32List { + U32Node *first; + U32Node *last; + u64 node_count; +}; + +typedef struct U64Node U64Node; +struct U64Node { + u64 *item; + U64Node *prev; + U64Node *next; +}; + +typedef struct U64List U64List; +struct U64List { + U64Node *first; + U64Node *last; + u64 node_count; +}; + +typedef struct F32Node F32Node; +struct F32Node { + f32 *item; + F32Node *prev; + F32Node *next; +}; + +typedef struct F32List F32List; +struct F32List { + F32Node *first; + F32Node *last; + u64 node_count; +}; + +typedef struct F64Node F64Node; +struct F64Node { + f64 *item; + F64Node *prev; + F64Node *next; +}; + +typedef struct F64List F64List; +struct F64List { + F64Node *first; + F64Node *last; + u64 node_count; +}; + +typedef struct F128Node F128Node; +struct F128Node { + f128 *item; + F128Node *prev; + F128Node *next; +}; + +typedef struct F128List F128List; +struct F128List { + F128Node *first; + F128Node *last; + u64 node_count; +}; + +typedef struct IptrNode IptrNode; +struct IptrNode { + iptr *item; + IptrNode *prev; + IptrNode *next; +}; + +typedef struct IptrList IptrList; +struct IptrList { + IptrNode *first; + IptrNode *last; + u64 node_count; +}; + +typedef struct UptrNode UptrNode; +struct UptrNode { + uptr *item; + UptrNode *prev; + UptrNode *next; +}; + +typedef struct UptrList UptrList; +struct UptrList { + UptrNode *first; + UptrNode *last; + u64 node_count; +}; + +Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); +void wapp_str8_list_push_front(Str8List *list, Str8Node *node); +void wapp_str8_list_push_back(Str8List *list, Str8Node *node); +void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index); +Str8Node *wapp_str8_list_pop_front(Str8List *list); +Str8Node *wapp_str8_list_pop_back(Str8List *list); +Str8Node *wapp_str8_list_remove(Str8List *list, u64 index); +void wapp_str8_list_empty(Str8List *list); +VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index); +void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node); +void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node); +void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index); +VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list); +VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list); +VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index); +void wapp_void_ptr_list_empty(VoidPList *list); +BoolNode *wapp_bool_list_get(const BoolList *list, u64 index); +void wapp_bool_list_push_front(BoolList *list, BoolNode *node); +void wapp_bool_list_push_back(BoolList *list, BoolNode *node); +void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index); +BoolNode *wapp_bool_list_pop_front(BoolList *list); +BoolNode *wapp_bool_list_pop_back(BoolList *list); +BoolNode *wapp_bool_list_remove(BoolList *list, u64 index); +void wapp_bool_list_empty(BoolList *list); +CharNode *wapp_char_list_get(const CharList *list, u64 index); +void wapp_char_list_push_front(CharList *list, CharNode *node); +void wapp_char_list_push_back(CharList *list, CharNode *node); +void wapp_char_list_insert(CharList *list, CharNode *node, u64 index); +CharNode *wapp_char_list_pop_front(CharList *list); +CharNode *wapp_char_list_pop_back(CharList *list); +CharNode *wapp_char_list_remove(CharList *list, u64 index); +void wapp_char_list_empty(CharList *list); +C8Node *wapp_c8_list_get(const C8List *list, u64 index); +void wapp_c8_list_push_front(C8List *list, C8Node *node); +void wapp_c8_list_push_back(C8List *list, C8Node *node); +void wapp_c8_list_insert(C8List *list, C8Node *node, u64 index); +C8Node *wapp_c8_list_pop_front(C8List *list); +C8Node *wapp_c8_list_pop_back(C8List *list); +C8Node *wapp_c8_list_remove(C8List *list, u64 index); +void wapp_c8_list_empty(C8List *list); +C16Node *wapp_c16_list_get(const C16List *list, u64 index); +void wapp_c16_list_push_front(C16List *list, C16Node *node); +void wapp_c16_list_push_back(C16List *list, C16Node *node); +void wapp_c16_list_insert(C16List *list, C16Node *node, u64 index); +C16Node *wapp_c16_list_pop_front(C16List *list); +C16Node *wapp_c16_list_pop_back(C16List *list); +C16Node *wapp_c16_list_remove(C16List *list, u64 index); +void wapp_c16_list_empty(C16List *list); +C32Node *wapp_c32_list_get(const C32List *list, u64 index); +void wapp_c32_list_push_front(C32List *list, C32Node *node); +void wapp_c32_list_push_back(C32List *list, C32Node *node); +void wapp_c32_list_insert(C32List *list, C32Node *node, u64 index); +C32Node *wapp_c32_list_pop_front(C32List *list); +C32Node *wapp_c32_list_pop_back(C32List *list); +C32Node *wapp_c32_list_remove(C32List *list, u64 index); +void wapp_c32_list_empty(C32List *list); +I8Node *wapp_i8_list_get(const I8List *list, u64 index); +void wapp_i8_list_push_front(I8List *list, I8Node *node); +void wapp_i8_list_push_back(I8List *list, I8Node *node); +void wapp_i8_list_insert(I8List *list, I8Node *node, u64 index); +I8Node *wapp_i8_list_pop_front(I8List *list); +I8Node *wapp_i8_list_pop_back(I8List *list); +I8Node *wapp_i8_list_remove(I8List *list, u64 index); +void wapp_i8_list_empty(I8List *list); +I16Node *wapp_i16_list_get(const I16List *list, u64 index); +void wapp_i16_list_push_front(I16List *list, I16Node *node); +void wapp_i16_list_push_back(I16List *list, I16Node *node); +void wapp_i16_list_insert(I16List *list, I16Node *node, u64 index); +I16Node *wapp_i16_list_pop_front(I16List *list); +I16Node *wapp_i16_list_pop_back(I16List *list); +I16Node *wapp_i16_list_remove(I16List *list, u64 index); +void wapp_i16_list_empty(I16List *list); +I32Node *wapp_i32_list_get(const I32List *list, u64 index); +void wapp_i32_list_push_front(I32List *list, I32Node *node); +void wapp_i32_list_push_back(I32List *list, I32Node *node); +void wapp_i32_list_insert(I32List *list, I32Node *node, u64 index); +I32Node *wapp_i32_list_pop_front(I32List *list); +I32Node *wapp_i32_list_pop_back(I32List *list); +I32Node *wapp_i32_list_remove(I32List *list, u64 index); +void wapp_i32_list_empty(I32List *list); +I64Node *wapp_i64_list_get(const I64List *list, u64 index); +void wapp_i64_list_push_front(I64List *list, I64Node *node); +void wapp_i64_list_push_back(I64List *list, I64Node *node); +void wapp_i64_list_insert(I64List *list, I64Node *node, u64 index); +I64Node *wapp_i64_list_pop_front(I64List *list); +I64Node *wapp_i64_list_pop_back(I64List *list); +I64Node *wapp_i64_list_remove(I64List *list, u64 index); +void wapp_i64_list_empty(I64List *list); +U8Node *wapp_u8_list_get(const U8List *list, u64 index); +void wapp_u8_list_push_front(U8List *list, U8Node *node); +void wapp_u8_list_push_back(U8List *list, U8Node *node); +void wapp_u8_list_insert(U8List *list, U8Node *node, u64 index); +U8Node *wapp_u8_list_pop_front(U8List *list); +U8Node *wapp_u8_list_pop_back(U8List *list); +U8Node *wapp_u8_list_remove(U8List *list, u64 index); +void wapp_u8_list_empty(U8List *list); +U16Node *wapp_u16_list_get(const U16List *list, u64 index); +void wapp_u16_list_push_front(U16List *list, U16Node *node); +void wapp_u16_list_push_back(U16List *list, U16Node *node); +void wapp_u16_list_insert(U16List *list, U16Node *node, u64 index); +U16Node *wapp_u16_list_pop_front(U16List *list); +U16Node *wapp_u16_list_pop_back(U16List *list); +U16Node *wapp_u16_list_remove(U16List *list, u64 index); +void wapp_u16_list_empty(U16List *list); +U32Node *wapp_u32_list_get(const U32List *list, u64 index); +void wapp_u32_list_push_front(U32List *list, U32Node *node); +void wapp_u32_list_push_back(U32List *list, U32Node *node); +void wapp_u32_list_insert(U32List *list, U32Node *node, u64 index); +U32Node *wapp_u32_list_pop_front(U32List *list); +U32Node *wapp_u32_list_pop_back(U32List *list); +U32Node *wapp_u32_list_remove(U32List *list, u64 index); +void wapp_u32_list_empty(U32List *list); +U64Node *wapp_u64_list_get(const U64List *list, u64 index); +void wapp_u64_list_push_front(U64List *list, U64Node *node); +void wapp_u64_list_push_back(U64List *list, U64Node *node); +void wapp_u64_list_insert(U64List *list, U64Node *node, u64 index); +U64Node *wapp_u64_list_pop_front(U64List *list); +U64Node *wapp_u64_list_pop_back(U64List *list); +U64Node *wapp_u64_list_remove(U64List *list, u64 index); +void wapp_u64_list_empty(U64List *list); +F32Node *wapp_f32_list_get(const F32List *list, u64 index); +void wapp_f32_list_push_front(F32List *list, F32Node *node); +void wapp_f32_list_push_back(F32List *list, F32Node *node); +void wapp_f32_list_insert(F32List *list, F32Node *node, u64 index); +F32Node *wapp_f32_list_pop_front(F32List *list); +F32Node *wapp_f32_list_pop_back(F32List *list); +F32Node *wapp_f32_list_remove(F32List *list, u64 index); +void wapp_f32_list_empty(F32List *list); +F64Node *wapp_f64_list_get(const F64List *list, u64 index); +void wapp_f64_list_push_front(F64List *list, F64Node *node); +void wapp_f64_list_push_back(F64List *list, F64Node *node); +void wapp_f64_list_insert(F64List *list, F64Node *node, u64 index); +F64Node *wapp_f64_list_pop_front(F64List *list); +F64Node *wapp_f64_list_pop_back(F64List *list); +F64Node *wapp_f64_list_remove(F64List *list, u64 index); +void wapp_f64_list_empty(F64List *list); +F128Node *wapp_f128_list_get(const F128List *list, u64 index); +void wapp_f128_list_push_front(F128List *list, F128Node *node); +void wapp_f128_list_push_back(F128List *list, F128Node *node); +void wapp_f128_list_insert(F128List *list, F128Node *node, u64 index); +F128Node *wapp_f128_list_pop_front(F128List *list); +F128Node *wapp_f128_list_pop_back(F128List *list); +F128Node *wapp_f128_list_remove(F128List *list, u64 index); +void wapp_f128_list_empty(F128List *list); +IptrNode *wapp_iptr_list_get(const IptrList *list, u64 index); +void wapp_iptr_list_push_front(IptrList *list, IptrNode *node); +void wapp_iptr_list_push_back(IptrList *list, IptrNode *node); +void wapp_iptr_list_insert(IptrList *list, IptrNode *node, u64 index); +IptrNode *wapp_iptr_list_pop_front(IptrList *list); +IptrNode *wapp_iptr_list_pop_back(IptrList *list); +IptrNode *wapp_iptr_list_remove(IptrList *list, u64 index); +void wapp_iptr_list_empty(IptrList *list); +UptrNode *wapp_uptr_list_get(const UptrList *list, u64 index); +void wapp_uptr_list_push_front(UptrList *list, UptrNode *node); +void wapp_uptr_list_push_back(UptrList *list, UptrNode *node); +void wapp_uptr_list_insert(UptrList *list, UptrNode *node, u64 index); +UptrNode *wapp_uptr_list_pop_front(UptrList *list); +UptrNode *wapp_uptr_list_pop_back(UptrList *list); +UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index); +void wapp_uptr_list_empty(UptrList *list); + +#ifdef WAPP_PLATFORM_CPP +END_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#endif // !DBL_LIST_H