101 lines
5.0 KiB
C
101 lines
5.0 KiB
C
// vim:fileencoding=utf-8:foldmethod=marker
|
|
|
|
#ifndef QUEUE_H
|
|
#define QUEUE_H
|
|
|
|
#include "../array/array.h"
|
|
#include "../mem/allocator/mem_allocator.h"
|
|
#include "../../common/aliases/aliases.h"
|
|
#include "../../common/platform/platform.h"
|
|
|
|
#ifdef WAPP_PLATFORM_CPP
|
|
BEGIN_C_LINKAGE
|
|
#endif // !WAPP_PLATFORM_CPP
|
|
|
|
typedef struct {
|
|
GenericArray items;
|
|
u64 front;
|
|
u64 back;
|
|
u64 count;
|
|
} GenericQueue;
|
|
|
|
// NOTE (Abdelrahman): GenericQueue typedefs for readability
|
|
typedef GenericQueue VoidPtrQueue;
|
|
typedef GenericQueue C8Queue;
|
|
typedef GenericQueue C16Queue;
|
|
typedef GenericQueue C32Queue;
|
|
typedef GenericQueue U8Queue;
|
|
typedef GenericQueue U16Queue;
|
|
typedef GenericQueue U32Queue;
|
|
typedef GenericQueue U64Queue;
|
|
typedef GenericQueue B8Queue;
|
|
typedef GenericQueue I8Queue;
|
|
typedef GenericQueue I16Queue;
|
|
typedef GenericQueue I32Queue;
|
|
typedef GenericQueue I64Queue;
|
|
typedef GenericQueue F32Queue;
|
|
typedef GenericQueue F64Queue;
|
|
typedef GenericQueue F128Queue;
|
|
typedef GenericQueue UptrQueue;
|
|
typedef GenericQueue IptrQueue;
|
|
typedef GenericQueue Str8Queue;
|
|
|
|
#ifdef WAPP_PLATFORM_CPP
|
|
#define wapp_queue(TYPE, CAPACITY) ([&]() { \
|
|
wapp_persist GenericArray arr = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED); \
|
|
wapp_persist GenericQueue queue = { \
|
|
arr, \
|
|
0, \
|
|
0, \
|
|
0, \
|
|
}; \
|
|
\
|
|
return queue; \
|
|
}())
|
|
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ([&]() { \
|
|
wapp_persist GenericQueue queue = { \
|
|
wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
|
0, \
|
|
0, \
|
|
0, \
|
|
}; \
|
|
\
|
|
return queue; \
|
|
}())
|
|
#else
|
|
#define wapp_queue(TYPE, CAPACITY) ((GenericQueue){ \
|
|
.items = wapp_array_with_capacity(TYPE, CAPACITY, ARRAY_INIT_FILLED), \
|
|
.front = 0, \
|
|
.back = 0, \
|
|
.count = 0, \
|
|
})
|
|
#define wapp_queue_alloc(TYPE, ALLOCATOR_PTR, CAPACITY) ((GenericQueue){ \
|
|
.items = wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
|
.front = 0, \
|
|
.back = 0, \
|
|
.count = 0, \
|
|
})
|
|
#endif // !WAPP_PLATFORM_CPP
|
|
|
|
#define wapp_queue_capacity(QUEUE_PTR) (wapp_array_capacity((QUEUE_PTR)->items))
|
|
#define wapp_queue_item_size(QUEUE_PTR) (wapp_array_item_size((QUEUE_PTR)->items))
|
|
#define wapp_queue_push(TYPE, QUEUE_PTR, VALUE_PTR) ( \
|
|
_queue_push(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
|
)
|
|
#define wapp_queue_push_alloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
|
|
_queue_push_alloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
|
)
|
|
#define wapp_queue_pop(TYPE, QUEUE_PTR) ( \
|
|
(TYPE *)_queue_pop(QUEUE_PTR, sizeof(TYPE)) \
|
|
)
|
|
|
|
void _queue_push(GenericQueue *queue, void *item, u64 item_size);
|
|
GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue, void *item, u64 item_size);
|
|
void *_queue_pop(GenericQueue *queue, u64 item_size);
|
|
|
|
#ifdef WAPP_PLATFORM_CPP
|
|
END_C_LINKAGE
|
|
#endif // !WAPP_PLATFORM_CPP
|
|
|
|
#endif // !QUEUE_H
|