No codegen doubly-linked list (#8)
Reviewed-on: #8 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit was merged in pull request #8.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#define _offset_pointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
|
||||
|
||||
void *_array_get(Array *array, u64 index, u64 item_size) {
|
||||
void *_array_get(GenericArray *array, u64 index, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -18,12 +18,12 @@ void *_array_get(Array *array, u64 index, u64 item_size) {
|
||||
return _offset_pointer(array->items, array->item_size * index);
|
||||
}
|
||||
|
||||
void _array_set(Array *array, u64 index, void *value, u64 item_size) {
|
||||
void _array_set(GenericArray *array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _array_get(array, index, item_size);
|
||||
memcpy(item, value, array->item_size);
|
||||
}
|
||||
|
||||
void _array_append_capped(Array *array, void *value, u64 item_size) {
|
||||
void _array_append_capped(GenericArray *array, void *value, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -34,7 +34,7 @@ void _array_append_capped(Array *array, void *value, u64 item_size) {
|
||||
_array_set(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _array_extend_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
@@ -48,7 +48,7 @@ void _array_extend_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
dst->count += copy_count;
|
||||
}
|
||||
|
||||
void _array_copy_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
@@ -60,16 +60,16 @@ void _array_copy_capped(Array *dst, const Array *src, u64 item_size) {
|
||||
dst->count = copy_count;
|
||||
}
|
||||
|
||||
Array *_array_append_alloc(const Allocator *allocator, Array *array, void *value, u64 item_size) {
|
||||
GenericArray *_array_append_alloc(const Allocator *allocator, GenericArray *array, void *value, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = array;
|
||||
GenericArray *output = array;
|
||||
|
||||
if (array->count >= array->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, array->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
goto RETURN_ARRAY_APPEND_ALLOC;
|
||||
@@ -83,18 +83,18 @@ RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
Array *_array_extend_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size) {
|
||||
GenericArray *_array_extend_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = dst;
|
||||
GenericArray *output = dst;
|
||||
|
||||
u64 remaining_capacity = dst->capacity - dst->count;
|
||||
if (src->count >= remaining_capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, dst->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, dst->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
@@ -108,17 +108,17 @@ RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
Array *_array_copy_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size) {
|
||||
GenericArray *_array_copy_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
|
||||
|
||||
Array *output = dst;
|
||||
GenericArray *output = dst;
|
||||
|
||||
if (src->count >= dst->capacity) {
|
||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2);
|
||||
output = (Array *)_array_alloc_capacity(allocator, new_capacity, src->item_size);
|
||||
output = (GenericArray *)_array_alloc_capacity(allocator, new_capacity, src->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_COPY_ALLOC;
|
||||
@@ -131,7 +131,7 @@ RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_array_pop(Array *array, u64 item_size) {
|
||||
void *_array_pop(GenericArray *array, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -144,7 +144,7 @@ void *_array_pop(Array *array, u64 item_size) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void _array_clear(Array *array, u64 item_size) {
|
||||
void _array_clear(GenericArray *array, u64 item_size) {
|
||||
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
|
||||
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
|
||||
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
|
||||
@@ -152,12 +152,12 @@ void _array_clear(Array *array, u64 item_size) {
|
||||
array->count = 0;
|
||||
}
|
||||
|
||||
Array *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size) {
|
||||
GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size) {
|
||||
wapp_runtime_assert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
Array *output = NULL;
|
||||
GenericArray *output = NULL;
|
||||
|
||||
u64 allocation_size = sizeof(Array) + item_size * capacity;
|
||||
u64 allocation_size = sizeof(GenericArray) + item_size * capacity;
|
||||
|
||||
output = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
if (!output) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415F415252
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
|
||||
#define _calc_array_count(TYPE, ...) wapp_misc_utils_va_args_count(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wapp_misc_utils_u64_round_up_pow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
@@ -61,7 +61,7 @@ BEGIN_C_LINKAGE
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((ELEM_TYPE *)_array_pop((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))); \
|
||||
return *((ELEM_TYPE *)_array_pop((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define wapp_array(ELEM_TYPE, ARRAY_TYPE, ...) \
|
||||
@@ -85,43 +85,53 @@ BEGIN_C_LINKAGE
|
||||
})
|
||||
#define wapp_array_pop(ELEM_TYPE, ARRAY_PTR) \
|
||||
(ARRAY_PTR != NULL && (ARRAY_PTR)->count > 0 ? \
|
||||
*((ELEM_TYPE *)_array_pop((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))) : \
|
||||
*((ELEM_TYPE *)_array_pop((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))) : \
|
||||
(ELEM_TYPE){0} \
|
||||
)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_array_get(ELEM_TYPE, ARRAY_PTR, INDEX) \
|
||||
((ELEM_TYPE *)_array_get((Array *)ARRAY_PTR, INDEX, sizeof(ELEM_TYPE)))
|
||||
#define wapp_array_set(ELEM_TYPE, ARRAY_PTR, INDEX, VALUE_PTR) \
|
||||
_array_set((Array *)ARRAY_PTR, INDEX, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_append_capped(ELEM_TYPE, ARRAY_PTR, VALUE_PTR) \
|
||||
_array_append_capped((Array *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_extend_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_extend_capped((Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_copy_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_copy_capped((Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_append_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, ARRAY_PTR, VALUE_PTR) \
|
||||
(ARRAY_TYPE *)_array_append_alloc(ALLOCATOR_PTR, (Array *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_extend_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_extend_alloc(ALLOCATOR_PTR, (Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_copy_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_copy_alloc(ALLOCATOR_PTR, (Array *)DST_ARRAY_PTR, (Array *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_clear(ELEM_TYPE, ARRAY_PTR) \
|
||||
_array_clear((Array *)ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_get(ELEM_TYPE, ARRAY_PTR, INDEX) \
|
||||
((ELEM_TYPE *)_array_get((GenericArray *)ARRAY_PTR, INDEX, sizeof(ELEM_TYPE)))
|
||||
#define wapp_array_set(ELEM_TYPE, ARRAY_PTR, INDEX, VALUE_PTR) \
|
||||
_array_set((GenericArray *)ARRAY_PTR, INDEX, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_append_capped(ELEM_TYPE, ARRAY_PTR, VALUE_PTR) \
|
||||
_array_append_capped((GenericArray *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_array_extend_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_extend_capped( \
|
||||
(GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_copy_capped(ELEM_TYPE, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
_array_copy_capped( \
|
||||
(GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_append_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, ARRAY_PTR, VALUE_PTR) \
|
||||
(ARRAY_TYPE *)_array_append_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)ARRAY_PTR, (void *)VALUE_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_extend_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_extend_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_copy_alloc(ELEM_TYPE, ARRAY_TYPE, ALLOCATOR_PTR, DST_ARRAY_PTR, SRC_ARRAY_PTR) \
|
||||
(ARRAY_TYPE *)_array_copy_alloc( \
|
||||
ALLOCATOR_PTR, (GenericArray *)DST_ARRAY_PTR, (GenericArray *)SRC_ARRAY_PTR, sizeof(ELEM_TYPE) \
|
||||
)
|
||||
#define wapp_array_clear(ELEM_TYPE, ARRAY_PTR) \
|
||||
_array_clear((GenericArray *)ARRAY_PTR, sizeof(ELEM_TYPE))
|
||||
|
||||
WAPP_DEF_ARRAY_TYPE(void, Array);
|
||||
WAPP_DEF_ARRAY_TYPE(void, GenericArray);
|
||||
|
||||
void *_array_get(Array *array, u64 index, u64 item_size);
|
||||
void _array_set(Array *array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(Array *array, void *value, u64 item_size);
|
||||
void _array_extend_capped(Array *dst, const Array *src, u64 item_size);
|
||||
void _array_copy_capped(Array *dst, const Array *src, u64 item_size);
|
||||
Array *_array_append_alloc(const Allocator *allocator, Array *array, void *value, u64 item_size);
|
||||
Array *_array_extend_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size);
|
||||
Array *_array_copy_alloc(const Allocator *allocator, Array *dst, const Array *src, u64 item_size);
|
||||
void *_array_pop(Array *array, u64 item_size);
|
||||
void _array_clear(Array *array, u64 item_size);
|
||||
Array *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
void *_array_get(GenericArray *array, u64 index, u64 item_size);
|
||||
void _array_set(GenericArray *array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(GenericArray *array, void *value, u64 item_size);
|
||||
void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
GenericArray *_array_append_alloc(const Allocator *allocator, GenericArray *array, void *value, u64 item_size);
|
||||
GenericArray *_array_extend_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
GenericArray *_array_copy_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size);
|
||||
void *_array_pop(GenericArray *array, u64 item_size);
|
||||
void _array_clear(GenericArray *array, u64 item_size);
|
||||
GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u64 item_size);
|
||||
|
||||
// Base array types
|
||||
typedef struct str8 Str8;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,7 @@
|
||||
/**
|
||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN.
|
||||
*/
|
||||
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
#include "../mem/allocator/mem_allocator.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
|
||||
@@ -12,506 +9,97 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_DBL_LIST_MAGIC (u64)0x57415f444c5354
|
||||
#define WAPP_DBL_NODE_MAGIC (u64)0x57415f444e44
|
||||
|
||||
#define WAPP_DEF_DBL_LIST_TYPE(T, NODE_NAME, LIST_NAME) \
|
||||
typedef struct NODE_NAME NODE_NAME; \
|
||||
struct NODE_NAME { \
|
||||
u64 magic; \
|
||||
T *item; \
|
||||
NODE_NAME *prev; \
|
||||
NODE_NAME *next; \
|
||||
u64 item_size; \
|
||||
}; \
|
||||
\
|
||||
typedef struct { \
|
||||
u64 magic; \
|
||||
NODE_NAME *first; \
|
||||
NODE_NAME *last; \
|
||||
u64 node_count; \
|
||||
u64 item_size; \
|
||||
} LIST_NAME
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_void_ptr_list_node(ITEM_PTR) VoidPNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_str8_list_node(ITEM_PTR) Str8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_b8_list_node(ITEM_PTR) B8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_char_list_node(ITEM_PTR) CharNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c8_list_node(ITEM_PTR) C8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c16_list_node(ITEM_PTR) C16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_c32_list_node(ITEM_PTR) C32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i8_list_node(ITEM_PTR) I8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i16_list_node(ITEM_PTR) I16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i32_list_node(ITEM_PTR) I32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_i64_list_node(ITEM_PTR) I64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u8_list_node(ITEM_PTR) U8Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u16_list_node(ITEM_PTR) U16Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u32_list_node(ITEM_PTR) U32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_u64_list_node(ITEM_PTR) U64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f32_list_node(ITEM_PTR) F32Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f64_list_node(ITEM_PTR) F64Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_f128_list_node(ITEM_PTR) F128Node{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_iptr_list_node(ITEM_PTR) IptrNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_uptr_list_node(ITEM_PTR) UptrNode{ITEM_PTR, nullptr, nullptr}
|
||||
#define wapp_dbl_list(ELEM_TYPE, LIST_TYPE) \
|
||||
LIST_TYPE{WAPP_DBL_LIST_MAGIC, nullptr, nullptr, 0, sizeof(ELEM_TYPE)}
|
||||
#define wapp_dbl_list_node(ELEM_TYPE, NODE_TYPE, ELEM_PTR) \
|
||||
NODE_TYPE{WAPP_DBL_NODE_MAGIC, ELEM_PTR, nullptr, nullptr, sizeof(ELEM_TYPE)}
|
||||
#else
|
||||
#define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
|
||||
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
||||
#define wapp_b8_list_node(ITEM_PTR) ((B8Node){.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})
|
||||
#define wapp_dbl_list(ELEM_TYPE, LIST_TYPE) ( \
|
||||
(LIST_TYPE){.magic = WAPP_DBL_LIST_MAGIC, .item_size = sizeof(ELEM_TYPE)} \
|
||||
)
|
||||
#define wapp_dbl_list_node(ELEM_TYPE, NODE_TYPE, ELEM_PTR) ( \
|
||||
(NODE_TYPE){.magic = WAPP_DBL_NODE_MAGIC, .item = ELEM_PTR, .item_size = sizeof(ELEM_TYPE)} \
|
||||
)
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#define wapp_dbl_list_alloc(ELEM_TYPE, LIST_TYPE, ALLOCATOR) \
|
||||
(LIST_TYPE *)_dbl_list_alloc(ALLOCATOR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_node_alloc(ELEM_TYPE, NODE_TYPE, ALLOCATOR) \
|
||||
(NODE_TYPE *)_dbl_list_node_alloc(ALLOCATOR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_get(ELEM_TYPE, NODE_TYPE, LIST_PTR, ELEM_INDEX) \
|
||||
(NODE_TYPE *)_dbl_list_get((GenericList *)LIST_PTR, ELEM_INDEX, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_push_front(ELEM_TYPE, LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_front((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_push_back(ELEM_TYPE, LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_back((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_insert(ELEM_TYPE, LIST_PTR, NODE_PTR, ELEM_INDEX) \
|
||||
_dbl_list_insert((GenericList *)LIST_PTR, (GenericNode *)NODE_PTR, ELEM_INDEX, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_pop_front(ELEM_TYPE, NODE_TYPE, LIST_PTR) \
|
||||
(NODE_TYPE *)_dbl_list_pop_front((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_pop_back(ELEM_TYPE, NODE_TYPE, LIST_PTR) \
|
||||
(NODE_TYPE *)_dbl_list_pop_back((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_remove(ELEM_TYPE, NODE_TYPE, LIST_PTR, ELEM_INDEX) \
|
||||
(NODE_TYPE *)_dbl_list_remove((GenericList *)LIST_PTR, ELEM_INDEX, sizeof(ELEM_TYPE))
|
||||
#define wapp_dbl_list_empty(ELEM_TYPE, LIST_PTR) \
|
||||
_dbl_list_empty((GenericList *)LIST_PTR, sizeof(ELEM_TYPE))
|
||||
|
||||
WAPP_DEF_DBL_LIST_TYPE(void, GenericNode, GenericList);
|
||||
|
||||
GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size);
|
||||
GenericNode *_dbl_list_node_alloc(const Allocator *allocator, u64 item_size);
|
||||
GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size);
|
||||
void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size);
|
||||
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size);
|
||||
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size);
|
||||
GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size);
|
||||
GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size);
|
||||
GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size);
|
||||
void _dbl_list_empty(GenericList *list, u64 item_size);
|
||||
|
||||
// Base list types
|
||||
typedef struct str8 Str8;
|
||||
|
||||
typedef struct GenericNode GenericNode;
|
||||
struct GenericNode {
|
||||
void *item;
|
||||
GenericNode *prev;
|
||||
GenericNode *next;
|
||||
};
|
||||
|
||||
typedef struct GenericList GenericList;
|
||||
struct GenericList {
|
||||
GenericNode *first;
|
||||
GenericNode *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 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 B8Node B8Node;
|
||||
struct B8Node {
|
||||
b8 *item;
|
||||
B8Node *prev;
|
||||
B8Node *next;
|
||||
};
|
||||
|
||||
typedef struct B8List B8List;
|
||||
struct B8List {
|
||||
B8Node *first;
|
||||
B8Node *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;
|
||||
};
|
||||
|
||||
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);
|
||||
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);
|
||||
B8Node *wapp_b8_list_get(const B8List *list, u64 index);
|
||||
void wapp_b8_list_push_front(B8List *list, B8Node *node);
|
||||
void wapp_b8_list_push_back(B8List *list, B8Node *node);
|
||||
void wapp_b8_list_insert(B8List *list, B8Node *node, u64 index);
|
||||
B8Node *wapp_b8_list_pop_front(B8List *list);
|
||||
B8Node *wapp_b8_list_pop_back(B8List *list);
|
||||
B8Node *wapp_b8_list_remove(B8List *list, u64 index);
|
||||
void wapp_b8_list_empty(B8List *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);
|
||||
WAPP_DEF_DBL_LIST_TYPE(void *, VoidPtrNode, VoidPtrList);
|
||||
WAPP_DEF_DBL_LIST_TYPE(c8 , C8Node , C8List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(c16 , C16Node , C16List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(c32 , C32Node , C32List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(u8 , U8Node , U8List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(u16 , U16Node , U16List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(u32 , U32Node , U32List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(u64 , U64Node , U64List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(b8 , B8Node , B8List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(i8 , I8Node , I8List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(i16 , I16Node , I16List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(i32 , I32Node , I32List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(i64 , I64Node , I64List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(f32 , F32Node , F32List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(f64 , F64Node , F64List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(f128 , F128Node , F128List);
|
||||
WAPP_DEF_DBL_LIST_TYPE(uptr , UptrNode , UptrList);
|
||||
WAPP_DEF_DBL_LIST_TYPE(iptr , IptrNode , IptrList);
|
||||
WAPP_DEF_DBL_LIST_TYPE(Str8 , Str8Node , Str8List);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -333,14 +333,14 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
Str8List *output = wapp_dbl_list_alloc(Str8, Str8List, allocator);
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node) {
|
||||
node->item = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
wapp_dbl_list_push_back(Str8, output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -358,10 +358,10 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
}
|
||||
|
||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node && before_str) {
|
||||
node->item = before_str;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
wapp_dbl_list_push_back(Str8, output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -373,10 +373,10 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
|
||||
// Ensure the last part of the string after the delimiter is added to the list
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node && rest) {
|
||||
node->item = rest;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
wapp_dbl_list_push_back(Str8, output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
@@ -386,14 +386,14 @@ RETURN_STR8_SPLIT:
|
||||
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
wapp_debug_assert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
Str8List *output = wapp_dbl_list_alloc(Str8, Str8List, allocator);
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node && full) {
|
||||
node->item = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
wapp_dbl_list_push_back(Str8, output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -410,10 +410,10 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
}
|
||||
|
||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node) {
|
||||
node->item = after_str;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
wapp_dbl_list_push_front(Str8, output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -423,10 +423,10 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
}
|
||||
|
||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
Str8Node *node = wapp_dbl_list_node_alloc(Str8, Str8Node, allocator);
|
||||
if (node && rest) {
|
||||
node->item = rest;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
wapp_dbl_list_push_front(Str8, output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
@@ -445,7 +445,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
||||
u64 node_index = 0;
|
||||
b8 running = node_index < list->node_count;
|
||||
while (running) {
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
node = wapp_dbl_list_get(Str8, Str8Node, list, node_index);
|
||||
if (!node) {
|
||||
break;
|
||||
}
|
||||
@@ -478,7 +478,7 @@ u64 wapp_str8_list_total_size(const Str8List *list) {
|
||||
u64 output = 0;
|
||||
b8 running = node_index < list->node_count;
|
||||
while (running) {
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
node = wapp_dbl_list_get(Str8, Str8Node, list, node_index);
|
||||
if (!node) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -119,23 +119,31 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
|
||||
/**
|
||||
* Str8 list utilities
|
||||
*/
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node([&]() { \
|
||||
wapp_persist Str8 str = wapp_str8_lit(STRING); \
|
||||
return &str; \
|
||||
}())
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node([&]() { \
|
||||
wapp_persist Str8 str = STRING; \
|
||||
return &str; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
u64 wapp_str8_list_total_size(const Str8List *list);
|
||||
|
||||
#ifdef WAPP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template <typename T>
|
||||
constexpr bool is_lvalue(T&&) {
|
||||
return std::is_lvalue_reference<T>{};
|
||||
}
|
||||
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node(Str8, Str8Node, [&]() { \
|
||||
wapp_persist Str8 str = wapp_str8_lit(STRING); \
|
||||
return &str; \
|
||||
}())
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node(Str8, Str8Node, [&]() { \
|
||||
if (is_lvalue(STRING)) { return &STRING; } \
|
||||
\
|
||||
wapp_persist Str8 str = STRING; \
|
||||
return &str; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node(Str8, Str8Node, &wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node(Str8, Str8Node, &(STRING))
|
||||
#endif // !WAPP_PLATFORM_CPP
|
||||
|
||||
#endif // !STR8_H
|
||||
|
||||
@@ -29,7 +29,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
}
|
||||
|
||||
// Handle first node
|
||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||
const Str8Node *first_node = wapp_dbl_list_get(Str8, Str8Node, parts, 0);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->item);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
@@ -106,7 +106,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.');
|
||||
} else {
|
||||
for (u64 i = 0; i < levels; ++i) {
|
||||
wapp_str8_list_pop_back(parts);
|
||||
wapp_dbl_list_pop_back(Str8, Str8Node, parts);
|
||||
}
|
||||
|
||||
u64 alignment = sizeof(void *) * 2;
|
||||
|
||||
@@ -62,7 +62,7 @@ u64 wapp_file_get_length(File *file) {
|
||||
return output;
|
||||
}
|
||||
|
||||
u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count) {
|
||||
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count) {
|
||||
wapp_debug_assert(dst_buf != NULL && file != NULL,
|
||||
"`dst_buf` and `file` should not be NULL.");
|
||||
|
||||
@@ -86,7 +86,7 @@ u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count) {
|
||||
return dst_buf->count;
|
||||
}
|
||||
|
||||
u64 wapp_file_write(const Array *src_buf, File *file, u64 item_count) {
|
||||
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count) {
|
||||
wapp_debug_assert(src_buf != NULL && file != NULL,
|
||||
"`src_buf` and `file` should not be NULL.");
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ File *wapp_file_open(Str8RO *filename, FileAccessMode mode);
|
||||
u64 wapp_file_get_current_position(File *file);
|
||||
i32 wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin);
|
||||
u64 wapp_file_get_length(File *file);
|
||||
u64 wapp_file_read(Array *dst_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_write(const Array *src_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count);
|
||||
u64 wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count);
|
||||
i32 wapp_file_flush(File *file);
|
||||
i32 wapp_file_close(File *file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user