Reformat array
This commit is contained in:
+20
-20
@@ -20,26 +20,26 @@ BEGIN_C_LINKAGE
|
||||
typedef struct WpStr8 WpStr8;
|
||||
|
||||
// NOTE (Abdelrahman): Typedefs to distinguish arrays from regular pointers
|
||||
typedef void *WpArray;
|
||||
typedef void **WpVoidPtrArray;
|
||||
typedef c8 *WpC8Array;
|
||||
typedef c16 *WpC16Array;
|
||||
typedef c32 *WpC32Array;
|
||||
typedef u8 *WpU8Array;
|
||||
typedef u16 *WpU16Array;
|
||||
typedef u32 *WpU32Array;
|
||||
typedef u64 *WpU64Array;
|
||||
typedef b8 *WpB8Array;
|
||||
typedef i8 *WpI8Array;
|
||||
typedef i16 *WpI16Array;
|
||||
typedef i32 *WpI32Array;
|
||||
typedef i64 *WpI64Array;
|
||||
typedef f32 *WpF32Array;
|
||||
typedef f64 *WpF64Array;
|
||||
typedef f128 *WpF128Array;
|
||||
typedef uptr *WpUptrArray;
|
||||
typedef iptr *WpIptrArray;
|
||||
typedef WpStr8 *WpStr8Array;
|
||||
typedef void *WpArray;
|
||||
typedef void **WpVoidPtrArray;
|
||||
typedef c8 *WpC8Array;
|
||||
typedef c16 *WpC16Array;
|
||||
typedef c32 *WpC32Array;
|
||||
typedef u8 *WpU8Array;
|
||||
typedef u16 *WpU16Array;
|
||||
typedef u32 *WpU32Array;
|
||||
typedef u64 *WpU64Array;
|
||||
typedef b8 *WpB8Array;
|
||||
typedef i8 *WpI8Array;
|
||||
typedef i16 *WpI16Array;
|
||||
typedef i32 *WpI32Array;
|
||||
typedef i64 *WpI64Array;
|
||||
typedef f32 *WpF32Array;
|
||||
typedef f64 *WpF64Array;
|
||||
typedef f128 *WpF128Array;
|
||||
typedef uptr *WpUptrArray;
|
||||
typedef iptr *WpIptrArray;
|
||||
typedef WpStr8 *WpStr8Array;
|
||||
|
||||
typedef enum {
|
||||
WP_ARRAY_INIT_NONE = 0,
|
||||
|
||||
@@ -7,46 +7,46 @@
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
|
||||
wp_intern GenericList _node_to_list(GenericNode *node, u64 item_size);
|
||||
wp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size);
|
||||
wp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size);
|
||||
wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size);
|
||||
wp_intern inline void _dblListValidate(const WpDblList *list, u64 item_size);
|
||||
wp_intern inline void _dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size);
|
||||
|
||||
GenericList *_dbl_list_alloc(const WpAllocator *allocator, u64 item_size) {
|
||||
WpDblList *_dblListAlloc(const WpAllocator *allocator, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
GenericList *list = wpMemAllocatorAlloc(allocator, sizeof(GenericList));
|
||||
WpDblList *list = wpMemAllocatorAlloc(allocator, sizeof(WpDblList));
|
||||
if (!list) { goto DBL_LIST_ALLOC_RETURN; }
|
||||
|
||||
memset((void *)list, 0, sizeof(GenericList));
|
||||
list->magic = WAPP_DBL_LIST_MAGIC;
|
||||
memset((void *)list, 0, sizeof(WpDblList));
|
||||
list->magic = WP_DBL_LIST_MAGIC;
|
||||
list->item_size = item_size;
|
||||
|
||||
DBL_LIST_ALLOC_RETURN:
|
||||
return list;
|
||||
}
|
||||
|
||||
GenericNode *_dbl_list_node_alloc(const WpAllocator *allocator, void *item, u64 item_size) {
|
||||
WpDblNode *_dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
GenericNode *node = wpMemAllocatorAlloc(allocator, sizeof(GenericNode));
|
||||
WpDblNode *node = wpMemAllocatorAlloc(allocator, sizeof(WpDblNode));
|
||||
if (!node) { goto DBL_LIST_NODE_ALLOC_RETURN; }
|
||||
|
||||
memset((void *)node, 0, sizeof(GenericNode));
|
||||
memset((void *)node, 0, sizeof(WpDblNode));
|
||||
node->item = item;
|
||||
node->header.magic = WAPP_DBL_NODE_MAGIC;
|
||||
node->header.magic = WP_DBL_NODE_MAGIC;
|
||||
node->header.item_size = item_size;
|
||||
|
||||
DBL_LIST_NODE_ALLOC_RETURN:
|
||||
return node;
|
||||
}
|
||||
|
||||
GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
wpRuntimeAssert(index < list->node_count, "`index` is out of bounds");
|
||||
|
||||
GenericNode *output = NULL;
|
||||
GenericNode *current = list->first;
|
||||
WpDblNode *output = NULL;
|
||||
WpDblNode *current = list->first;
|
||||
for (u64 i = 1; i <= index; ++i) {
|
||||
current = current->header.next;
|
||||
}
|
||||
@@ -56,12 +56,12 @@ GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dbl_list_node_validate(list, node, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
|
||||
GenericList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -70,7 +70,7 @@ void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
GenericNode *first = list->first;
|
||||
WpDblNode *first = list->first;
|
||||
if (first) {
|
||||
first->header.prev = node_list.last;
|
||||
}
|
||||
@@ -79,12 +79,12 @@ void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
node_list.last->header.next = first;
|
||||
}
|
||||
|
||||
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dbl_list_node_validate(list, node, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
|
||||
GenericList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -93,7 +93,7 @@ void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
GenericNode *last = list->last;
|
||||
WpDblNode *last = list->last;
|
||||
if (last) {
|
||||
last->header.next = node_list.first;
|
||||
}
|
||||
@@ -102,29 +102,29 @@ void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
|
||||
node_list.first->header.prev = last;
|
||||
}
|
||||
|
||||
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size) {
|
||||
void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dbl_list_node_validate(list, node, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
|
||||
if (index == 0) {
|
||||
_dbl_list_push_front(list, node, item_size);
|
||||
_dblListPushFront(list, node, item_size);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
_dbl_list_push_back(list, node, item_size);
|
||||
_dblListPushBack(list, node, item_size);
|
||||
return;
|
||||
}
|
||||
|
||||
GenericNode *dst_node = _dbl_list_get(list, index, item_size);
|
||||
WpDblNode *dst_node = _dblListGet(list, index, item_size);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
GenericList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
GenericNode *prev = dst_node->header.prev;
|
||||
WpDblNode *prev = dst_node->header.prev;
|
||||
|
||||
dst_node->header.prev = node_list.last;
|
||||
prev->header.next = node_list.first;
|
||||
@@ -133,11 +133,11 @@ void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_
|
||||
node_list.last->header.next = dst_node;
|
||||
}
|
||||
|
||||
GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size) {
|
||||
WpDblNode *_dblListPopFront(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
|
||||
GenericNode *output = NULL;
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
if (list->node_count == 0) {
|
||||
goto RETURN_LIST_POP_FRONT;
|
||||
@@ -146,7 +146,7 @@ GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size) {
|
||||
output = list->first;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size};
|
||||
*list = (WpDblList){.magic = WP_DBL_LIST_MAGIC, .item_size = item_size};
|
||||
goto RETURN_LIST_POP_FRONT;
|
||||
}
|
||||
|
||||
@@ -159,11 +159,11 @@ RETURN_LIST_POP_FRONT:
|
||||
return output;
|
||||
}
|
||||
|
||||
GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size) {
|
||||
WpDblNode *_dblListPopBack(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
|
||||
GenericNode *output = NULL;
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
if (list->node_count == 0) {
|
||||
goto RETURN_LIST_POP_BACK;
|
||||
@@ -172,7 +172,7 @@ GenericNode *_dbl_list_pop_back(GenericList *list, u64 item_size) {
|
||||
output = list->last;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size};
|
||||
*list = (WpDblList){.magic = WP_DBL_LIST_MAGIC, .item_size = item_size};
|
||||
goto RETURN_LIST_POP_BACK;
|
||||
}
|
||||
|
||||
@@ -185,21 +185,21 @@ RETURN_LIST_POP_BACK:
|
||||
return output;
|
||||
}
|
||||
|
||||
GenericNode *_dbl_list_remove(GenericList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *_dblListRemove(WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
|
||||
GenericNode *output = NULL;
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
if (index == 0) {
|
||||
output = _dbl_list_pop_front(list, item_size);
|
||||
output = _dblListPopFront(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = _dbl_list_pop_back(list, item_size);
|
||||
output = _dblListPopBack(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = _dbl_list_get(list, index, item_size);
|
||||
output = _dblListGet(list, index, item_size);
|
||||
if (!output) {
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
@@ -215,19 +215,19 @@ RETURN_LIST_REMOVE:
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dbl_list_empty(GenericList *list, u64 item_size) {
|
||||
void _dblListEmpty(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dbl_list_validate(list, item_size);
|
||||
_dblListValidate(list, item_size);
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
_dbl_list_pop_back(list, item_size);
|
||||
_dblListPopBack(list, item_size);
|
||||
}
|
||||
}
|
||||
|
||||
wp_intern GenericList _node_to_list(GenericNode *node, u64 item_size) {
|
||||
GenericList output = {
|
||||
.magic = WAPP_DBL_LIST_MAGIC,
|
||||
wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size) {
|
||||
WpDblList output = {
|
||||
.magic = WP_DBL_LIST_MAGIC,
|
||||
.first = node,
|
||||
.last = node,
|
||||
.node_count = 1,
|
||||
@@ -247,13 +247,13 @@ wp_intern GenericList _node_to_list(GenericNode *node, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
wp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size) {
|
||||
wpRuntimeAssert(list->magic == WAPP_DBL_LIST_MAGIC, "`list` isn't a valid wapp list type");
|
||||
wp_intern inline void _dblListValidate(const WpDblList *list, u64 item_size) {
|
||||
wpRuntimeAssert(list->magic == WP_DBL_LIST_MAGIC, "`list` isn't a valid wp list type");
|
||||
wpRuntimeAssert(list->item_size == item_size, "Invalid item provided");
|
||||
}
|
||||
|
||||
wp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size) {
|
||||
wpRuntimeAssert(node->header.magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp node type");
|
||||
wp_intern inline void _dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size) {
|
||||
wpRuntimeAssert(node->header.magic == WP_DBL_NODE_MAGIC, "`node` isn't a valid wp node type");
|
||||
wpRuntimeAssert(list->item_size == node->header.item_size, "Mismatched `list` and `node` types");
|
||||
wpRuntimeAssert(node->header.item_size == item_size, "Invalid item provided");
|
||||
}
|
||||
|
||||
+103
-103
@@ -11,20 +11,20 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_DBL_LIST_MAGIC (u64)0x57415f444c5354
|
||||
#define WAPP_DBL_NODE_MAGIC (u64)0x57415f444e44
|
||||
#define WP_DBL_LIST_MAGIC (u64)0x57415f444c5354
|
||||
#define WP_DBL_NODE_MAGIC (u64)0x57415f444e44
|
||||
|
||||
typedef struct GenericNode GenericNode;
|
||||
typedef struct WpDblNode WpDblNode;
|
||||
|
||||
typedef struct {
|
||||
u64 magic;
|
||||
u64 item_size;
|
||||
GenericNode *prev;
|
||||
GenericNode *next;
|
||||
} NodeHeader;
|
||||
WpDblNode *prev;
|
||||
WpDblNode *next;
|
||||
} WpDblNodeHeader;
|
||||
|
||||
struct GenericNode {
|
||||
NodeHeader header;
|
||||
struct WpDblNode {
|
||||
WpDblNodeHeader header;
|
||||
void *item;
|
||||
};
|
||||
|
||||
@@ -32,150 +32,150 @@ typedef struct {
|
||||
u64 magic;
|
||||
u64 node_count;
|
||||
u64 item_size;
|
||||
GenericNode *first;
|
||||
GenericNode *last;
|
||||
} GenericList;
|
||||
WpDblNode *first;
|
||||
WpDblNode *last;
|
||||
} WpDblList;
|
||||
|
||||
// NOTE (Abdelrahman): GenericList typedefs for readability
|
||||
typedef GenericList VoidPtrList;
|
||||
typedef GenericList C8List;
|
||||
typedef GenericList C16List;
|
||||
typedef GenericList C32List;
|
||||
typedef GenericList U8List;
|
||||
typedef GenericList U16List;
|
||||
typedef GenericList U32List;
|
||||
typedef GenericList U64List;
|
||||
typedef GenericList B8List;
|
||||
typedef GenericList I8List;
|
||||
typedef GenericList I16List;
|
||||
typedef GenericList I32List;
|
||||
typedef GenericList I64List;
|
||||
typedef GenericList F32List;
|
||||
typedef GenericList F64List;
|
||||
typedef GenericList F128List;
|
||||
typedef GenericList UptrList;
|
||||
typedef GenericList IptrList;
|
||||
typedef GenericList WpStr8List;
|
||||
// NOTE (Abdelrahman): WpDblList typedefs for readability
|
||||
typedef WpDblList WpVoidPtrList;
|
||||
typedef WpDblList WpC8List;
|
||||
typedef WpDblList WpC16List;
|
||||
typedef WpDblList WpC32List;
|
||||
typedef WpDblList WpU8List;
|
||||
typedef WpDblList WpU16List;
|
||||
typedef WpDblList WpU32List;
|
||||
typedef WpDblList WpU64List;
|
||||
typedef WpDblList WpB8List;
|
||||
typedef WpDblList WpI8List;
|
||||
typedef WpDblList WpI16List;
|
||||
typedef WpDblList WpI32List;
|
||||
typedef WpDblList WpI64List;
|
||||
typedef WpDblList WpF32List;
|
||||
typedef WpDblList WpF64List;
|
||||
typedef WpDblList WpF128List;
|
||||
typedef WpDblList WpUptrList;
|
||||
typedef WpDblList WpIptrList;
|
||||
typedef WpDblList WpStr8List;
|
||||
|
||||
// NOTE (Abdelrahman): GenericNode typedefs for readability
|
||||
typedef GenericNode VoidPtrNode;
|
||||
typedef GenericNode C8Node;
|
||||
typedef GenericNode C16Node;
|
||||
typedef GenericNode C32Node;
|
||||
typedef GenericNode U8Node;
|
||||
typedef GenericNode U16Node;
|
||||
typedef GenericNode U32Node;
|
||||
typedef GenericNode U64Node;
|
||||
typedef GenericNode B8Node;
|
||||
typedef GenericNode I8Node;
|
||||
typedef GenericNode I16Node;
|
||||
typedef GenericNode I32Node;
|
||||
typedef GenericNode I64Node;
|
||||
typedef GenericNode F32Node;
|
||||
typedef GenericNode F64Node;
|
||||
typedef GenericNode F128Node;
|
||||
typedef GenericNode UptrNode;
|
||||
typedef GenericNode IptrNode;
|
||||
typedef GenericNode WpStr8Node;
|
||||
// NOTE (Abdelrahman): WpDblNode typedefs for readability
|
||||
typedef WpDblNode WpVoidPtrNode;
|
||||
typedef WpDblNode WpC8Node;
|
||||
typedef WpDblNode WpC16Node;
|
||||
typedef WpDblNode WpC32Node;
|
||||
typedef WpDblNode WpU8Node;
|
||||
typedef WpDblNode WpU16Node;
|
||||
typedef WpDblNode WpU32Node;
|
||||
typedef WpDblNode WpU64Node;
|
||||
typedef WpDblNode WpB8Node;
|
||||
typedef WpDblNode WpI8Node;
|
||||
typedef WpDblNode WpI16Node;
|
||||
typedef WpDblNode WpI32Node;
|
||||
typedef WpDblNode WpI64Node;
|
||||
typedef WpDblNode WpF32Node;
|
||||
typedef WpDblNode WpF64Node;
|
||||
typedef WpDblNode WpF128Node;
|
||||
typedef WpDblNode WpUptrNode;
|
||||
typedef WpDblNode WpIptrNode;
|
||||
typedef WpDblNode WpStr8Node;
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wapp_dbl_list(TYPE) \
|
||||
GenericList{WAPP_DBL_LIST_MAGIC, 0, sizeof(TYPE), nullptr, nullptr}
|
||||
#define _dbl_list_node(TYPE, ITEM_PTR) ([&]() { \
|
||||
wp_persist GenericNode node = { \
|
||||
NodeHeader{WAPP_DBL_NODE_MAGIC, sizeof(TYPE), nullptr, nullptr}, \
|
||||
#define wpDblList(TYPE) \
|
||||
WpDblList{WP_DBL_LIST_MAGIC, 0, sizeof(TYPE), nullptr, nullptr}
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ([&]() { \
|
||||
wp_persist WpDblNode node = { \
|
||||
WpDblNodeHeader{WP_DBL_NODE_MAGIC, sizeof(TYPE), nullptr, nullptr}, \
|
||||
ITEM_PTR, \
|
||||
}; \
|
||||
\
|
||||
return &node; \
|
||||
}())
|
||||
#else
|
||||
#define wapp_dbl_list(TYPE) ( \
|
||||
(GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = sizeof(TYPE)} \
|
||||
#define wpDblList(TYPE) ( \
|
||||
(WpDblList){.magic = WP_DBL_LIST_MAGIC, .item_size = sizeof(TYPE)} \
|
||||
)
|
||||
#define _dbl_list_node(TYPE, ITEM_PTR) ( \
|
||||
&((GenericNode){.header = {.magic = WAPP_DBL_NODE_MAGIC, .item_size = sizeof(TYPE)}, \
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ( \
|
||||
&((WpDblNode){.header = {.magic = WP_DBL_NODE_MAGIC, .item_size = sizeof(TYPE)}, \
|
||||
.item = ITEM_PTR}) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wapp_dbl_list_alloc(TYPE, ALLOCATOR) \
|
||||
(_dbl_list_alloc(ALLOCATOR, sizeof(TYPE)))
|
||||
#define wapp_dbl_list_get(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)(_dbl_list_get(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
#define wapp_dbl_list_get_node(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
(_dbl_list_get(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wapp_dbl_list_get_node_item(TYPE, NODE_PTR) \
|
||||
#define wpDblListAlloc(TYPE, ALLOCATOR) \
|
||||
(_dblListAlloc(ALLOCATOR, sizeof(TYPE)))
|
||||
#define wpDblListGet(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
#define wpDblListGet_node(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListGet_node_item(TYPE, NODE_PTR) \
|
||||
((TYPE *)( \
|
||||
(NODE_PTR == NULL) ? \
|
||||
NULL : \
|
||||
(NODE_PTR)->item \
|
||||
))
|
||||
#define wapp_dbl_list_push_front(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dbl_list_push_front(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wapp_dbl_list_push_back(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dbl_list_push_back(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wapp_dbl_list_insert(TYPE, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dbl_list_insert(LIST_PTR, _dbl_list_node(TYPE, ITEM_PTR), \
|
||||
#define wpDblListPush_front(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wpDblListPush_back(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wpDblListInsert(TYPE, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dblListInsert(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wapp_dbl_list_push_front_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dbl_list_push_front(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
#define wpDblListPush_front_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_dbl_list_push_back_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dbl_list_push_back(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
#define wpDblListPush_back_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_dbl_list_insert_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dbl_list_insert(LIST_PTR, _dbl_list_node_alloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
#define wpDblListInsert_alloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dblListInsert(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wapp_dbl_list_pop_front(TYPE, LIST_PTR) \
|
||||
#define wpDblListPop_front(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dbl_list_pop_front(LIST_PTR, sizeof(TYPE))->item \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wapp_dbl_list_pop_back(TYPE, LIST_PTR) \
|
||||
#define wpDblListPop_back(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dbl_list_pop_back(LIST_PTR, sizeof(TYPE))->item \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wapp_dbl_list_remove(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
#define wpDblListRemove(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dbl_list_remove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wapp_dbl_list_pop_front_node(TYPE, LIST_PTR) \
|
||||
#define wpDblListPop_front_node(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dbl_list_pop_front(LIST_PTR, sizeof(TYPE)) \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wapp_dbl_list_pop_back_node(TYPE, LIST_PTR) \
|
||||
#define wpDblListPop_back_node(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dbl_list_pop_back(LIST_PTR, sizeof(TYPE)) \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wapp_dbl_list_remove_node(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
#define wpDblListRemove_node(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dbl_list_remove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
)
|
||||
#define wapp_dbl_list_empty(TYPE, LIST_PTR) \
|
||||
(_dbl_list_empty(LIST_PTR, sizeof(TYPE)))
|
||||
#define wpDblListEmpty(TYPE, LIST_PTR) \
|
||||
(_dblListEmpty(LIST_PTR, sizeof(TYPE)))
|
||||
|
||||
GenericList *_dbl_list_alloc(const WpAllocator *allocator, u64 item_size);
|
||||
GenericNode *_dbl_list_node_alloc(const WpAllocator *allocator, void *item, 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);
|
||||
WpDblList *_dblListAlloc(const WpAllocator *allocator, u64 item_size);
|
||||
WpDblNode *_dblListNodeAlloc(const WpAllocator *allocator, void *item, u64 item_size);
|
||||
WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size);
|
||||
void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size);
|
||||
void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size);
|
||||
WpDblNode *_dblListPopFront(WpDblList *list, u64 item_size);
|
||||
WpDblNode *_dblListPopBack(WpDblList *list, u64 item_size);
|
||||
WpDblNode *_dblListRemove(WpDblList *list, u64 index, u64 item_size);
|
||||
void _dblListEmpty(WpDblList *list, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
Reference in New Issue
Block a user