Add free array and queue utils
Release / release (push) Successful in 7s

This commit is contained in:
2026-07-05 20:51:17 +01:00
parent 02372cb644
commit 2a20362b44
5 changed files with 65 additions and 45 deletions
+9 -4
View File
@@ -42,7 +42,7 @@ typedef WpQueue WpStr8Queue;
#ifdef WP_PLATFORM_CPP
#define wpQueue(TYPE, CAPACITY) ([&]() { \
wp_persist WpArray arr = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED); \
wp_persist WpArray arr = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED); \
wp_persist WpQueue queue = { \
arr, \
0, \
@@ -54,7 +54,7 @@ typedef WpQueue WpStr8Queue;
}())
#define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \
wp_persist WpQueue queue = { \
wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
0, \
0, \
0, \
@@ -64,13 +64,13 @@ typedef WpQueue WpStr8Queue;
}())
#else
#define wpQueue(TYPE, CAPACITY) ((WpQueue){ \
.items = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED), \
.items = wpArrayWithCapacity(TYPE, CAPACITY, WP_ARRAY_INIT_FILLED), \
.front = 0, \
.back = 0, \
.count = 0, \
})
#define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((WpQueue){ \
.items = wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
.items = wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
.front = 0, \
.back = 0, \
.count = 0, \
@@ -88,6 +88,11 @@ typedef WpQueue WpStr8Queue;
#define wpQueuePop(TYPE, QUEUE_PTR) ( \
(TYPE *)_queuePop(QUEUE_PTR, sizeof(TYPE)) \
)
#define wpQueueDealloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR) \
(wpArrayDealloc(TYPE, ALLOCATOR_PTR, &((QUEUE_PTR)->items)), \
(QUEUE_PTR)->front = 0, \
(QUEUE_PTR)->back = 0, \
(QUEUE_PTR)->count = 0)
void _queuePush(WpQueue *queue, void *item, u64 item_size);
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);