Standardize naming conventions #12

Merged
abdelrahman merged 26 commits from naming-conventions into main 2026-06-26 17:17:27 +00:00
4 changed files with 78 additions and 78 deletions
Showing only changes of commit c4134c4017 - Show all commits
+7 -7
View File
@@ -6,7 +6,7 @@
#include "../../common/misc/misc_utils.h" #include "../../common/misc/misc_utils.h"
#include <string.h> #include <string.h>
void _queue_push(GenericQueue *queue, void *item, u64 item_size) { void _queuePush(WpQueue *queue, void *item, u64 item_size) {
wpDebugAssert(queue != NULL, "`queue` should not be NULL"); wpDebugAssert(queue != NULL, "`queue` should not be NULL");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type"); wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
@@ -22,12 +22,12 @@ void _queue_push(GenericQueue *queue, void *item, u64 item_size) {
} }
} }
GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queue, void *item, u64 item_size) { WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size) {
wpDebugAssert(allocator != NULL && queue != NULL && item != NULL, wpDebugAssert(allocator != NULL && queue != NULL && item != NULL,
"`allocator`, `queue` and `item` should not be NULL"); "`allocator`, `queue` and `item` should not be NULL");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type"); wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
GenericQueue *output = queue; WpQueue *output = queue;
u64 capacity = wapp_array_capacity(queue->items); u64 capacity = wapp_array_capacity(queue->items);
@@ -36,7 +36,7 @@ GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queu
if (queue_full) { if (queue_full) {
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2); u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2);
u64 array_size = _array_calc_alloc_size(new_capacity, item_size); u64 array_size = _array_calc_alloc_size(new_capacity, item_size);
u64 alloc_size = sizeof(GenericQueue) + array_size; u64 alloc_size = sizeof(WpQueue) + array_size;
void *buffer = wpMemAllocatorAlloc(allocator, alloc_size); void *buffer = wpMemAllocatorAlloc(allocator, alloc_size);
if (!buffer) { if (!buffer) {
goto RETURN_QUEUE_PUSH_ALLOC; goto RETURN_QUEUE_PUSH_ALLOC;
@@ -44,7 +44,7 @@ GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queu
memset((void *)buffer, 0, alloc_size); memset((void *)buffer, 0, alloc_size);
output = (GenericQueue *)buffer; output = (WpQueue *)buffer;
output->items = _array_from_preallocated_buffer((void *)(output + 1), array_size, ARRAY_INIT_FILLED, item_size); output->items = _array_from_preallocated_buffer((void *)(output + 1), array_size, ARRAY_INIT_FILLED, item_size);
// NOTE (Abdelrahman): When the queue is full, the front and back indices should // NOTE (Abdelrahman): When the queue is full, the front and back indices should
@@ -84,13 +84,13 @@ GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queu
output->count = queue->count; output->count = queue->count;
} }
_queue_push(output, item, item_size); _queuePush(output, item, item_size);
RETURN_QUEUE_PUSH_ALLOC: RETURN_QUEUE_PUSH_ALLOC:
return output; return output;
} }
void *_queue_pop(GenericQueue *queue, u64 item_size) { void *_queuePop(WpQueue *queue, u64 item_size) {
wpDebugAssert(queue != NULL, "`queue` should not be NULL"); wpDebugAssert(queue != NULL, "`queue` should not be NULL");
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type"); wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
+39 -39
View File
@@ -17,33 +17,33 @@ typedef struct {
u64 front; u64 front;
u64 back; u64 back;
u64 count; u64 count;
} GenericQueue; } WpQueue;
// NOTE (Abdelrahman): GenericQueue typedefs for readability // NOTE (Abdelrahman): WpQueue typedefs for readability
typedef GenericQueue VoidPtrQueue; typedef WpQueue WpVoidPtrQueue;
typedef GenericQueue C8Queue; typedef WpQueue WpC8Queue;
typedef GenericQueue C16Queue; typedef WpQueue WpC16Queue;
typedef GenericQueue C32Queue; typedef WpQueue WpC32Queue;
typedef GenericQueue U8Queue; typedef WpQueue WpU8Queue;
typedef GenericQueue U16Queue; typedef WpQueue WpU16Queue;
typedef GenericQueue U32Queue; typedef WpQueue WpU32Queue;
typedef GenericQueue U64Queue; typedef WpQueue WpU64Queue;
typedef GenericQueue B8Queue; typedef WpQueue WpB8Queue;
typedef GenericQueue I8Queue; typedef WpQueue WpI8Queue;
typedef GenericQueue I16Queue; typedef WpQueue WpI16Queue;
typedef GenericQueue I32Queue; typedef WpQueue WpI32Queue;
typedef GenericQueue I64Queue; typedef WpQueue WpI64Queue;
typedef GenericQueue F32Queue; typedef WpQueue WpF32Queue;
typedef GenericQueue F64Queue; typedef WpQueue WpF64Queue;
typedef GenericQueue F128Queue; typedef WpQueue WpF128Queue;
typedef GenericQueue UptrQueue; typedef WpQueue WpUptrQueue;
typedef GenericQueue IptrQueue; typedef WpQueue WpIptrQueue;
typedef GenericQueue WpStr8Queue; typedef WpQueue WpStr8Queue;
#ifdef WP_PLATFORM_CPP #ifdef WP_PLATFORM_CPP
#define wapp_queue(TYPE, CAPACITY) ([&]() { \ #define wpQueue(TYPE, CAPACITY) ([&]() { \
wp_persist GenericArray arr = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED); \ wp_persist GenericArray arr = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED); \
wp_persist GenericQueue queue = { \ wp_persist WpQueue queue = { \
arr, \ arr, \
0, \ 0, \
0, \ 0, \
@@ -52,8 +52,8 @@ typedef GenericQueue WpStr8Queue;
\ \
return queue; \ return queue; \
}()) }())
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \ #define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \
wp_persist GenericQueue queue = { \ wp_persist WpQueue queue = { \
wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \ wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
0, \ 0, \
0, \ 0, \
@@ -63,13 +63,13 @@ typedef GenericQueue WpStr8Queue;
return queue; \ return queue; \
}()) }())
#else #else
#define wapp_queue(TYPE, CAPACITY) ((GenericQueue){ \ #define wpQueue(TYPE, CAPACITY) ((WpQueue){ \
.items = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED), \ .items = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED), \
.front = 0, \ .front = 0, \
.back = 0, \ .back = 0, \
.count = 0, \ .count = 0, \
}) })
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((GenericQueue){ \ #define wpQueueAlloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((WpQueue){ \
.items = wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \ .items = wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
.front = 0, \ .front = 0, \
.back = 0, \ .back = 0, \
@@ -77,21 +77,21 @@ typedef GenericQueue WpStr8Queue;
}) })
#endif // !WP_PLATFORM_CPP #endif // !WP_PLATFORM_CPP
#define wapp_queue_capacity(QUEUE_PTR) (wapp_array_capacity((QUEUE_PTR)->items)) #define wpQueueCapacity(QUEUE_PTR) (wapp_array_capacity((QUEUE_PTR)->items))
#define wapp_queue_item_size(QUEUE_PTR) (wapp_array_item_size((QUEUE_PTR)->items)) #define wpQueueItemSize(QUEUE_PTR) (wapp_array_item_size((QUEUE_PTR)->items))
#define wapp_queue_push(TYPE, QUEUE_PTR, VALUE_PTR) ( \ #define wpQueuePush(TYPE, QUEUE_PTR, VALUE_PTR) ( \
_queue_push(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \ _queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
) )
#define wapp_queue_push_alloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \ #define wpQueuePushAlloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
_queue_push_alloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \ _queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
) )
#define wapp_queue_pop(TYPE, QUEUE_PTR) ( \ #define wpQueuePop(TYPE, QUEUE_PTR) ( \
(TYPE *)_queue_pop(QUEUE_PTR, sizeof(TYPE)) \ (TYPE *)_queuePop(QUEUE_PTR, sizeof(TYPE)) \
) )
void _queue_push(GenericQueue *queue, void *item, u64 item_size); void _queuePush(WpQueue *queue, void *item, u64 item_size);
GenericQueue *_queue_push_alloc(const WpAllocator *allocator, GenericQueue *queue, void *item, u64 item_size); WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);
void *_queue_pop(GenericQueue *queue, u64 item_size); void *_queuePop(WpQueue *queue, u64 item_size);
#ifdef WP_PLATFORM_CPP #ifdef WP_PLATFORM_CPP
END_C_LINKAGE END_C_LINKAGE
+16 -16
View File
@@ -6,11 +6,11 @@
#define CAPACITY 8 #define CAPACITY 8
WpTestFuncResult test_queue_push(void) { WpTestFuncResult test_queue_push(void) {
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
@@ -24,40 +24,40 @@ WpTestFuncResult test_queue_push(void) {
WpTestFuncResult test_queue_push_alloc(void) { WpTestFuncResult test_queue_push_alloc(void) {
WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64)); WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64));
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
i32 item = 8; i32 item = 8;
u64 new_capacity = CAPACITY * 2; u64 new_capacity = CAPACITY * 2;
I32Queue *new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item); WpI32Queue *new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
if (new_queue && new_queue != &queue) { if (new_queue && new_queue != &queue) {
queue = *new_queue; queue = *new_queue;
} }
u64 capacity = wapp_queue_capacity(&queue); u64 capacity = wpQueueCapacity(&queue);
result = result && capacity == new_capacity; result = result && capacity == new_capacity;
for (u64 i = 0; i < 2; ++i) { for (u64 i = 0; i < 2; ++i) {
wapp_queue_pop(i32, &queue); wpQueuePop(i32, &queue);
} }
u64 remaining = wapp_queue_capacity(&queue) - queue.count; u64 remaining = wpQueueCapacity(&queue) - queue.count;
for (u64 i = 0; i < remaining; ++i) { for (u64 i = 0; i < remaining; ++i) {
item = (i32)(remaining + i); item = (i32)(remaining + i);
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
++item; ++item;
new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item); new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
if (new_queue && new_queue != &queue) { if (new_queue && new_queue != &queue) {
queue = *new_queue; queue = *new_queue;
} }
result = result && wapp_queue_capacity(&queue) == new_capacity * 2; result = result && wpQueueCapacity(&queue) == new_capacity * 2;
i32 *arr = (i32 *)queue.items; i32 *arr = (i32 *)queue.items;
for (u64 i = 0; i < queue.count; ++i) { for (u64 i = 0; i < queue.count; ++i) {
@@ -71,26 +71,26 @@ WpTestFuncResult test_queue_push_alloc(void) {
} }
WpTestFuncResult test_queue_pop(void) { WpTestFuncResult test_queue_pop(void) {
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
u64 half_count = queue.count / 2; u64 half_count = queue.count / 2;
for (u64 i = 0; i < half_count; ++i) { for (u64 i = 0; i < half_count; ++i) {
i32 *value = wapp_queue_pop(i32, &queue); i32 *value = wpQueuePop(i32, &queue);
result = result && value != NULL && *value == (i32)i; result = result && value != NULL && *value == (i32)i;
} }
for (u64 i = 0; i < half_count; ++i) { for (u64 i = 0; i < half_count; ++i) {
i32 item = (i32)i + CAPACITY; i32 item = (i32)i + CAPACITY;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 *value = wapp_queue_pop(i32, &queue); i32 *value = wpQueuePop(i32, &queue);
result = result && value != NULL && *value == (i32)half_count + (i32)i; result = result && value != NULL && *value == (i32)half_count + (i32)i;
} }
+16 -16
View File
@@ -4,11 +4,11 @@
#define CAPACITY 8 #define CAPACITY 8
WpTestFuncResult test_queue_push(void) { WpTestFuncResult test_queue_push(void) {
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
@@ -22,40 +22,40 @@ WpTestFuncResult test_queue_push(void) {
WpTestFuncResult test_queue_push_alloc(void) { WpTestFuncResult test_queue_push_alloc(void) {
WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64)); WpAllocator arena = wapp_mem_arena_allocator_init(MiB(64));
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
i32 item = 8; i32 item = 8;
u64 new_capacity = CAPACITY * 2; u64 new_capacity = CAPACITY * 2;
I32Queue *new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item); WpI32Queue *new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
if (new_queue && new_queue != &queue) { if (new_queue && new_queue != &queue) {
queue = *new_queue; queue = *new_queue;
} }
u64 capacity = wapp_queue_capacity(&queue); u64 capacity = wpQueueCapacity(&queue);
result = result && capacity == new_capacity; result = result && capacity == new_capacity;
for (u64 i = 0; i < 2; ++i) { for (u64 i = 0; i < 2; ++i) {
wapp_queue_pop(i32, &queue); wpQueuePop(i32, &queue);
} }
u64 remaining = wapp_queue_capacity(&queue) - queue.count; u64 remaining = wpQueueCapacity(&queue) - queue.count;
for (u64 i = 0; i < remaining; ++i) { for (u64 i = 0; i < remaining; ++i) {
item = (i32)(remaining + i); item = (i32)(remaining + i);
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
++item; ++item;
new_queue = wapp_queue_push_alloc(i32, &arena, &queue, &item); new_queue = wpQueuePushAlloc(i32, &arena, &queue, &item);
if (new_queue && new_queue != &queue) { if (new_queue && new_queue != &queue) {
queue = *new_queue; queue = *new_queue;
} }
result = result && wapp_queue_capacity(&queue) == new_capacity * 2; result = result && wpQueueCapacity(&queue) == new_capacity * 2;
i32 *arr = (i32 *)queue.items; i32 *arr = (i32 *)queue.items;
for (u64 i = 0; i < queue.count; ++i) { for (u64 i = 0; i < queue.count; ++i) {
@@ -69,26 +69,26 @@ WpTestFuncResult test_queue_push_alloc(void) {
} }
WpTestFuncResult test_queue_pop(void) { WpTestFuncResult test_queue_pop(void) {
I32Queue queue = wapp_queue(i32, CAPACITY); WpI32Queue queue = wpQueue(i32, CAPACITY);
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 item = (i32)i; i32 item = (i32)i;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
b8 result = true; b8 result = true;
u64 half_count = queue.count / 2; u64 half_count = queue.count / 2;
for (u64 i = 0; i < half_count; ++i) { for (u64 i = 0; i < half_count; ++i) {
i32 *value = wapp_queue_pop(i32, &queue); i32 *value = wpQueuePop(i32, &queue);
result = result && value != NULL && *value == (i32)i; result = result && value != NULL && *value == (i32)i;
} }
for (u64 i = 0; i < half_count; ++i) { for (u64 i = 0; i < half_count; ++i) {
i32 item = (i32)i + CAPACITY; i32 item = (i32)i + CAPACITY;
wapp_queue_push(i32, &queue, &item); wpQueuePush(i32, &queue, &item);
} }
for (u64 i = 0; i < CAPACITY; ++i) { for (u64 i = 0; i < CAPACITY; ++i) {
i32 *value = wapp_queue_pop(i32, &queue); i32 *value = wpQueuePop(i32, &queue);
result = result && value != NULL && *value == (i32)half_count + (i32)i; result = result && value != NULL && *value == (i32)half_count + (i32)i;
} }