This commit is contained in:
+72
-72
@@ -7,81 +7,81 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define _arrayHeader(ARRAY) (WpArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(WpArrayHeader) * -1))
|
||||
#define arrayHeader(ARRAY) (WpArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(WpArrayHeader) * -1))
|
||||
|
||||
wp_persist inline void _arrayValidate(const WpArray array, u64 item_size);
|
||||
wp_persist inline void arrayValidate(const WpArray array, u64 item_size);
|
||||
|
||||
u64 _arrayCount(WpArray array) {
|
||||
u64 arrayCount(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->count;
|
||||
}
|
||||
|
||||
u64 _arrayCapacity(WpArray array) {
|
||||
u64 arrayCapacity(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->capacity;
|
||||
}
|
||||
|
||||
u64 _arrayItemSize(WpArray array) {
|
||||
u64 arrayItemSize(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->item_size;
|
||||
}
|
||||
|
||||
void _arraySetCount(WpArray array, u64 count) {
|
||||
void arraySetCount(WpArray array, u64 count) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
header->count = count;
|
||||
}
|
||||
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size) {
|
||||
void *arrayGet(WpArray array, u64 index, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(index < header->count, "`index` is out of bounds");
|
||||
|
||||
return wpMiscUtilsOffsetPointer(array, header->item_size * index);
|
||||
}
|
||||
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _arrayGet(array, index, item_size);
|
||||
void arraySet(WpArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = arrayGet(array, index, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
memcpy(item, value, header->item_size);
|
||||
}
|
||||
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size) {
|
||||
void arrayAppendCapped(WpArray array, void *value, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count >= header->capacity) { return; }
|
||||
|
||||
u64 index = (header->count)++;
|
||||
_arraySet(array, index, value, item_size);
|
||||
arraySet(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
void arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
|
||||
u64 copy_count = src_header->count < remaining_capacity ? src_header->count : remaining_capacity;
|
||||
@@ -90,94 +90,94 @@ void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size) {
|
||||
dst_header->count += copy_count;
|
||||
}
|
||||
|
||||
void _arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size) {
|
||||
void arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size) {
|
||||
wpRuntimeAssert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
_arrayClear(dst, item_size);
|
||||
arrayClear(dst, item_size);
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 copy_count = src_header->count < dst_header->capacity ? src_header->count : dst_header->capacity;
|
||||
memcpy((void *)dst, (void *)src, copy_count * src_header->item_size);
|
||||
dst_header->count = copy_count;
|
||||
}
|
||||
|
||||
WpArray _arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArray arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArray output = array;
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count >= header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity, flags,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity, flags,
|
||||
header->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
goto RETURN_ARRAY_APPEND_ALLOC;
|
||||
}
|
||||
_arrayCopyCapped(output, array, item_size);
|
||||
arrayCopyCapped(output, array, item_size);
|
||||
}
|
||||
|
||||
_arrayAppendCapped(output, value, item_size);
|
||||
arrayAppendCapped(output, value, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpArray _arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArray output = dst;
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
u64 remaining_capacity = dst_header->capacity - dst_header->count;
|
||||
if (src_header->count >= remaining_capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, dst_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
}
|
||||
_arrayCopyCapped(output, dst, item_size);
|
||||
arrayCopyCapped(output, dst, item_size);
|
||||
}
|
||||
|
||||
_arrayExtendCappend(output, src, item_size);
|
||||
arrayExtendCappend(output, src, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
|
||||
_arrayValidate(dst, item_size);
|
||||
_arrayValidate(src, item_size);
|
||||
arrayValidate(dst, item_size);
|
||||
arrayValidate(src, item_size);
|
||||
|
||||
WpArray output = dst;
|
||||
|
||||
WpArrayHeader *src_header = _arrayHeader(src);
|
||||
WpArrayHeader *dst_header = _arrayHeader(dst);
|
||||
WpArrayHeader *src_header = arrayHeader(src);
|
||||
WpArrayHeader *dst_header = arrayHeader(dst);
|
||||
if (src_header->count >= dst_header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
output = (WpArray )arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, src_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
@@ -185,61 +185,61 @@ WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray
|
||||
}
|
||||
}
|
||||
|
||||
_arrayCopyCapped(output, src, item_size);
|
||||
arrayCopyCapped(output, src, item_size);
|
||||
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
arraySetCount(output, arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_arrayPop(WpArray array, u64 item_size) {
|
||||
void *arrayPop(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
if (header->count == 0) { return NULL; }
|
||||
|
||||
u64 index = header->count - 1;
|
||||
void *out = _arrayGet(array, index, item_size);
|
||||
void *out = arrayGet(array, index, item_size);
|
||||
--(header->count);
|
||||
return out;
|
||||
}
|
||||
|
||||
void _arrayClear(WpArray array, u64 item_size) {
|
||||
void arrayClear(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_arrayValidate(array, item_size);
|
||||
arrayValidate(array, item_size);
|
||||
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
header->count = 0;
|
||||
}
|
||||
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size) {
|
||||
u64 arrayCalcAllocSize(u64 capacity, u64 item_size) {
|
||||
return sizeof(WpArrayHeader) + item_size * capacity;
|
||||
}
|
||||
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
WpArray arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
WpArray output = NULL;
|
||||
|
||||
u64 allocation_size = _arrayCalcAllocSize(capacity, item_size);
|
||||
u64 allocation_size = arrayCalcAllocSize(capacity, item_size);
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, allocation_size);
|
||||
if (!buffer) {
|
||||
goto RETURN_ARRAY_ALLOC;
|
||||
}
|
||||
|
||||
output = _arrayFromPreallocatedBuffer(buffer, allocation_size, flags, item_size);
|
||||
output = arrayFromPreallocatedBuffer(buffer, allocation_size, flags, item_size);
|
||||
|
||||
RETURN_ARRAY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
WpArray arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(buffer != NULL, "`buffer` should not be NULL");
|
||||
|
||||
@@ -259,18 +259,18 @@ WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitF
|
||||
return output;
|
||||
}
|
||||
|
||||
void _arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size) {
|
||||
void arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
u64 capacity = wpArrayCapacity(*array);
|
||||
u64 allocation_size = _arrayCalcAllocSize(capacity, item_size);
|
||||
void *header = (void *)_arrayHeader(*array);
|
||||
u64 allocation_size = arrayCalcAllocSize(capacity, item_size);
|
||||
void *header = (void *)arrayHeader(*array);
|
||||
wpMemAllocatorFree(allocator, &header, allocation_size);
|
||||
*array = NULL;
|
||||
}
|
||||
|
||||
wp_persist inline void _arrayValidate(const WpArray array, u64 item_size) {
|
||||
WpArrayHeader *header = _arrayHeader(array);
|
||||
wp_persist inline void arrayValidate(const WpArray array, u64 item_size) {
|
||||
WpArrayHeader *header = arrayHeader(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
wpRuntimeAssert(item_size == header->item_size, "Invalid item type provided");
|
||||
}
|
||||
|
||||
+73
-73
@@ -14,8 +14,8 @@ BEGIN_C_LINKAGE
|
||||
|
||||
#define WP_ARRAY_MAGIC wpU64Const(0x57415f415252)
|
||||
|
||||
#define _calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
#define calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
typedef struct WpStr8 WpStr8;
|
||||
|
||||
@@ -48,17 +48,17 @@ typedef enum {
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpArray(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
u64 capacity = calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
\
|
||||
TYPE items[_calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
TYPE items[calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
\
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + _calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
sizeof(WpArrayHeader) + calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = _calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->count = calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
u8 *buf = (u8 *)(header + 1); \
|
||||
@@ -78,25 +78,25 @@ typedef enum {
|
||||
return (TYPE *)(header + 1); \
|
||||
}())
|
||||
#define wpArrayPop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0) { \
|
||||
if (ARRAY == NULL || arrayCount((WpArray)ARRAY) == 0) { \
|
||||
TYPE result{}; \
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
return *((TYPE *)arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define _stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
#define stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
TYPE items[SIZE]; \
|
||||
wpMiscUtilsReservePadding(sizeof(WpArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wpArray(TYPE, ...) \
|
||||
((TYPE *)( \
|
||||
(_stackArray(TYPE, _calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
(stackArray(TYPE, calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
.header = { \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = _calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.count = calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {__VA_ARGS__}, \
|
||||
@@ -104,7 +104,7 @@ typedef enum {
|
||||
))
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) \
|
||||
((TYPE *)( \
|
||||
(_stackArray(TYPE, CAPACITY)){ \
|
||||
(stackArray(TYPE, CAPACITY)){ \
|
||||
.header = { \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
@@ -115,71 +115,71 @@ typedef enum {
|
||||
}.items \
|
||||
))
|
||||
#define wpArrayPop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(ARRAY == NULL || arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(TYPE){0} : \
|
||||
*((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
*((TYPE *)arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpArrayCount(ARRAY) \
|
||||
(_arrayCount((WpArray)ARRAY))
|
||||
(arrayCount((WpArray)ARRAY))
|
||||
#define wpArrayCapacity(ARRAY) \
|
||||
(_arrayCapacity((WpArray)ARRAY))
|
||||
(arrayCapacity((WpArray)ARRAY))
|
||||
#define wpArrayItemSize(ARRAY) \
|
||||
(_arrayItemSize((WpArray)ARRAY))
|
||||
(arrayItemSize((WpArray)ARRAY))
|
||||
#define wpArraySetCount(ARRAY, COUNT) \
|
||||
(_arraySetCount((WpArray)ARRAY, COUNT))
|
||||
(arraySetCount((WpArray)ARRAY, COUNT))
|
||||
#define wpArrayGet(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArraySet(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
(arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayAppendCapped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
(arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayExtendCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayAppendAlloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayExtendAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCopyAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
((TYPE *)arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayClear(TYPE, ARRAY) \
|
||||
(_arrayClear((WpArray)ARRAY, \
|
||||
(arrayClear((WpArray)ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) _arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
((TYPE *)arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wpArrayFromPreallcatedBuffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
((TYPE *)_array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
((TYPE *)array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
// Only needed for allocators like malloc where each allocation has to be freed on its own.
|
||||
// No need to use it for allocators like Arena.
|
||||
#define wpArrayDealloc(TYPE, ALLOCATOR_PTR, ARRAY_DPTR) \
|
||||
(_arrayDealloc(ALLOCATOR_PTR, (WpArray *)ARRAY_DPTR, sizeof(TYPE)))
|
||||
(arrayDealloc(ALLOCATOR_PTR, (WpArray *)ARRAY_DPTR, sizeof(TYPE)))
|
||||
|
||||
|
||||
typedef struct WpArrayHeader WpArrayHeader;
|
||||
@@ -190,29 +190,29 @@ struct WpArrayHeader {
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
u64 _arrayCount(WpArray array);
|
||||
u64 _arrayCapacity(WpArray array);
|
||||
u64 _arrayItemSize(WpArray array);
|
||||
void _arraySetCount(WpArray array, u64 count);
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size);
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size);
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size);
|
||||
void _arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size);
|
||||
void _arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size);
|
||||
WpArray _arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
u64 arrayCount(WpArray array);
|
||||
u64 arrayCapacity(WpArray array);
|
||||
u64 arrayItemSize(WpArray array);
|
||||
void arraySetCount(WpArray array, u64 count);
|
||||
void *arrayGet(WpArray array, u64 index, u64 item_size);
|
||||
void arraySet(WpArray array, u64 index, void *value, u64 item_size);
|
||||
void arrayAppendCapped(WpArray array, void *value, u64 item_size);
|
||||
void arrayExtendCappend(WpArray dst, const WpArray src, u64 item_size);
|
||||
void arrayCopyCapped(WpArray dst, const WpArray src, u64 item_size);
|
||||
WpArray arrayAppendAlloc(const WpAllocator *allocator, WpArray array, void *value,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayExtendAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
WpArray _arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArray arrayCopyAlloc(const WpAllocator *allocator, WpArray dst, const WpArray src,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
void *_arrayPop(WpArray array, u64 item_size);
|
||||
void _arrayClear(WpArray array, u64 item_size);
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size);
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
void *arrayPop(WpArray array, u64 item_size);
|
||||
void arrayClear(WpArray array, u64 item_size);
|
||||
u64 arrayCalcAllocSize(u64 capacity, u64 item_size);
|
||||
WpArray arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
WpArray arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
void _arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size);
|
||||
void arrayDealloc(const WpAllocator *allocator, WpArray *array, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
#include "../../common/platform/platform.h"
|
||||
#include <stddef.h>
|
||||
|
||||
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);
|
||||
wp_intern WpDblList nodeToList(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);
|
||||
|
||||
WpDblList *_dblListAlloc(const WpAllocator *allocator, u64 item_size) {
|
||||
WpDblList *dblListAlloc(const WpAllocator *allocator, u64 item_size) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
WpDblList *list = wpMemAllocatorAlloc(allocator, sizeof(WpDblList));
|
||||
@@ -25,7 +25,7 @@ DBL_LIST_ALLOC_RETURN:
|
||||
return list;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListNodeAlloc(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");
|
||||
|
||||
WpDblNode *node = wpMemAllocatorAlloc(allocator, sizeof(WpDblNode));
|
||||
@@ -40,9 +40,9 @@ DBL_LIST_NODE_ALLOC_RETURN:
|
||||
return node;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
wpRuntimeAssert(index < list->node_count, "`index` is out of bounds");
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
@@ -56,12 +56,12 @@ WpDblNode *_dblListGet(const WpDblList *list, u64 index, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dblListPushFront(WpDblList *list, WpDblNode *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");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -79,12 +79,12 @@ void _dblListPushFront(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
node_list.last->header.next = first;
|
||||
}
|
||||
|
||||
void _dblListPushBack(WpDblList *list, WpDblNode *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");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
@@ -102,25 +102,25 @@ void _dblListPushBack(WpDblList *list, WpDblNode *node, u64 item_size) {
|
||||
node_list.first->header.prev = last;
|
||||
}
|
||||
|
||||
void _dblListInsert(WpDblList *list, WpDblNode *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");
|
||||
_dblListValidate(list, item_size);
|
||||
_dblListNodeValidate(list, node, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
dblListNodeValidate(list, node, item_size);
|
||||
|
||||
if (index == 0) {
|
||||
_dblListPushFront(list, node, item_size);
|
||||
dblListPushFront(list, node, item_size);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
_dblListPushBack(list, node, item_size);
|
||||
dblListPushBack(list, node, item_size);
|
||||
return;
|
||||
}
|
||||
|
||||
WpDblNode *dst_node = _dblListGet(list, index, item_size);
|
||||
WpDblNode *dst_node = dblListGet(list, index, item_size);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
WpDblList node_list = _node_to_list(node, item_size);
|
||||
WpDblList node_list = nodeToList(node, item_size);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
@@ -133,9 +133,9 @@ void _dblListInsert(WpDblList *list, WpDblNode *node, u64 index, u64 item_size)
|
||||
node_list.last->header.next = dst_node;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListPopFront(WpDblList *list, u64 item_size) {
|
||||
WpDblNode *dblListPopFront(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
@@ -159,9 +159,9 @@ RETURN_LIST_POP_FRONT:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListPopBack(WpDblList *list, u64 item_size) {
|
||||
WpDblNode *dblListPopBack(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
@@ -185,21 +185,21 @@ RETURN_LIST_POP_BACK:
|
||||
return output;
|
||||
}
|
||||
|
||||
WpDblNode *_dblListRemove(WpDblList *list, u64 index, u64 item_size) {
|
||||
WpDblNode *dblListRemove(WpDblList *list, u64 index, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
WpDblNode *output = NULL;
|
||||
|
||||
if (index == 0) {
|
||||
output = _dblListPopFront(list, item_size);
|
||||
output = dblListPopFront(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = _dblListPopBack(list, item_size);
|
||||
output = dblListPopBack(list, item_size);
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = _dblListGet(list, index, item_size);
|
||||
output = dblListGet(list, index, item_size);
|
||||
if (!output) {
|
||||
goto RETURN_LIST_REMOVE;
|
||||
}
|
||||
@@ -215,17 +215,17 @@ RETURN_LIST_REMOVE:
|
||||
return output;
|
||||
}
|
||||
|
||||
void _dblListEmpty(WpDblList *list, u64 item_size) {
|
||||
void dblListEmpty(WpDblList *list, u64 item_size) {
|
||||
wpDebugAssert(list != NULL, "`list` should not be NULL");
|
||||
_dblListValidate(list, item_size);
|
||||
dblListValidate(list, item_size);
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
_dblListPopBack(list, item_size);
|
||||
dblListPopBack(list, item_size);
|
||||
}
|
||||
}
|
||||
|
||||
wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size) {
|
||||
wp_intern WpDblList nodeToList(WpDblNode *node, u64 item_size) {
|
||||
WpDblList output = {
|
||||
.magic = WP_DBL_LIST_MAGIC,
|
||||
.first = node,
|
||||
@@ -247,12 +247,12 @@ wp_intern WpDblList _node_to_list(WpDblNode *node, u64 item_size) {
|
||||
return output;
|
||||
}
|
||||
|
||||
wp_intern inline void _dblListValidate(const WpDblList *list, u64 item_size) {
|
||||
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 _dblListNodeValidate(const WpDblList *list, const WpDblNode *node, u64 item_size) {
|
||||
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");
|
||||
|
||||
@@ -81,7 +81,7 @@ typedef WpDblNode WpStr8Node;
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpDblList(TYPE) \
|
||||
WpDblList{WP_DBL_LIST_MAGIC, 0, sizeof(TYPE), nullptr, nullptr}
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ([&]() { \
|
||||
#define dblListNode(TYPE, ITEM_PTR) ([&]() { \
|
||||
wp_persist WpDblNode node = { \
|
||||
WpDblNodeHeader{WP_DBL_NODE_MAGIC, sizeof(TYPE), nullptr, nullptr}, \
|
||||
ITEM_PTR, \
|
||||
@@ -93,18 +93,18 @@ typedef WpDblNode WpStr8Node;
|
||||
#define wpDblList(TYPE) ( \
|
||||
(WpDblList){.magic = WP_DBL_LIST_MAGIC, .item_size = sizeof(TYPE)} \
|
||||
)
|
||||
#define _dblListNode(TYPE, ITEM_PTR) ( \
|
||||
#define dblListNode(TYPE, ITEM_PTR) ( \
|
||||
&((WpDblNode){.header = {.magic = WP_DBL_NODE_MAGIC, .item_size = sizeof(TYPE)}, \
|
||||
.item = ITEM_PTR}) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpDblListAlloc(TYPE, ALLOCATOR) \
|
||||
(_dblListAlloc(ALLOCATOR, sizeof(TYPE)))
|
||||
(dblListAlloc(ALLOCATOR, sizeof(TYPE)))
|
||||
#define wpDblListGet(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
((TYPE *)(dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item))
|
||||
#define wpDblListGetNode(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
(_dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
(dblListGet(LIST_PTR, ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListGetNodeItem(TYPE, NODE_PTR) \
|
||||
((TYPE *)( \
|
||||
(NODE_PTR == NULL) ? \
|
||||
@@ -112,70 +112,70 @@ typedef WpDblNode WpStr8Node;
|
||||
(NODE_PTR)->item \
|
||||
))
|
||||
#define wpDblListPushFront(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
(dblListPushFront(LIST_PTR, dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
#define wpDblListPushBack(TYPE, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNode(TYPE, ITEM_PTR), sizeof(TYPE)))
|
||||
(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), \
|
||||
(dblListInsert(LIST_PTR, dblListNode(TYPE, ITEM_PTR), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListPushFrontAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushFront(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListPushFront(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wpDblListPushBackAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR) \
|
||||
(_dblListPushBack(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListPushBack(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
sizeof(TYPE)))
|
||||
#define wpDblListInsertAlloc(TYPE, ALLOCATOR, LIST_PTR, ITEM_PTR, ITEM_INDEX) \
|
||||
(_dblListInsert(LIST_PTR, _dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
(dblListInsert(LIST_PTR, dblListNodeAlloc(ALLOCATOR, ITEM_PTR, sizeof(TYPE)), \
|
||||
ITEM_INDEX, sizeof(TYPE)))
|
||||
#define wpDblListPopFront(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE))->item \
|
||||
dblListPopFront(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListPopBack(TYPE, LIST_PTR) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE))->item \
|
||||
dblListPopBack(LIST_PTR, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListRemove(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
((TYPE *)( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE))->item \
|
||||
))
|
||||
#define wpDblListPopFrontNode(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopFront(LIST_PTR, sizeof(TYPE)) \
|
||||
dblListPopFront(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListPopBackNode(TYPE, LIST_PTR) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0) ? \
|
||||
NULL : \
|
||||
_dblListPopBack(LIST_PTR, sizeof(TYPE)) \
|
||||
dblListPopBack(LIST_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListRemoveNode(TYPE, LIST_PTR, ITEM_INDEX) \
|
||||
( \
|
||||
(LIST_PTR == NULL || (LIST_PTR)->node_count == 0 || ITEM_INDEX >= (LIST_PTR)->node_count) ? \
|
||||
NULL : \
|
||||
_dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
dblListRemove(LIST_PTR, ITEM_INDEX, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpDblListEmpty(TYPE, LIST_PTR) \
|
||||
(_dblListEmpty(LIST_PTR, sizeof(TYPE)))
|
||||
(dblListEmpty(LIST_PTR, sizeof(TYPE)))
|
||||
|
||||
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);
|
||||
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
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void _validateIO(const WpMur3HasherIO *io);
|
||||
wp_intern inline u64 _fmix64(u64 k);
|
||||
wp_intern inline void validateIO(const WpMur3HasherIO *io);
|
||||
wp_intern inline u64 fmix64(u64 k);
|
||||
|
||||
void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
WpMur3HasherIO *io = (WpMur3HasherIO *)hasher_io;
|
||||
_validateIO(io);
|
||||
validateIO(io);
|
||||
|
||||
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
||||
|
||||
@@ -85,8 +85,8 @@ void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
h1 = _fmix64(h1);
|
||||
h2 = _fmix64(h2);
|
||||
h1 = fmix64(h1);
|
||||
h2 = fmix64(h2);
|
||||
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
@@ -95,11 +95,11 @@ void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
io->hash[1] = h2;
|
||||
}
|
||||
|
||||
wp_intern inline void _validateIO(const WpMur3HasherIO *io) {
|
||||
wp_intern inline void validateIO(const WpMur3HasherIO *io) {
|
||||
wpRuntimeAssert(io->magic == WP_MUR3_HASHER_MAGIC, "Invalid Murmur3 hash IO");
|
||||
}
|
||||
|
||||
wp_intern inline u64 _fmix64(u64 k) {
|
||||
wp_intern inline u64 fmix64(u64 k) {
|
||||
k ^= k >> 33;
|
||||
k *= wpU64Const(0xff51afd7ed558ccd);
|
||||
k ^= k >> 33;
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io);
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io);
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
#define _u32To8LE(p, v) \
|
||||
(p)[0] = (u8)((v)); \
|
||||
@@ -46,17 +46,17 @@ wp_intern inline b8 _checkRounds(const WpSipHasherParams *params);
|
||||
|
||||
void wpSipHasher128(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher128IO *io = (WpSipHasher128IO *)hasher_io;
|
||||
_validate128IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
validate128IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
||||
}
|
||||
|
||||
void wpSipHasher64(WpStream *bytes, void *hasher_io) {
|
||||
WpSipHasher64IO *io = (WpSipHasher64IO *)hasher_io;
|
||||
_validate64IO(io);
|
||||
_siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
validate64IO(io);
|
||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
||||
}
|
||||
|
||||
wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
||||
u64 outlen) {
|
||||
const u8 *kk = (const u8 *)¶ms->key;
|
||||
u64 inlen = bytes->count * bytes->item_size;
|
||||
@@ -157,19 +157,19 @@ wp_intern inline void _siphash(WpStream *bytes, const WpSipHasherParams *params,
|
||||
_u64To8LE(out + 8, b);
|
||||
}
|
||||
|
||||
wp_intern inline void _validate128IO(const WpSipHasher128IO *io) {
|
||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_128_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 128 IO");
|
||||
}
|
||||
|
||||
wp_intern inline void _validate64IO(const WpSipHasher64IO *io) {
|
||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io) {
|
||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_64_MAGIC;
|
||||
b8 rounds = _checkRounds(&io->params);
|
||||
b8 rounds = checkRounds(&io->params);
|
||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 64 IO");
|
||||
}
|
||||
|
||||
wp_intern inline b8 _checkRounds(const WpSipHasherParams *params) {
|
||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params) {
|
||||
b8 rounds24 = params->compression == 2 && params->finalisation == 4;
|
||||
b8 rounds48 = params->compression == 4 && params->finalisation == 8;
|
||||
return rounds24 || rounds48;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include <string.h>
|
||||
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
void queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
@@ -14,7 +14,7 @@ void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
if (queue->count >= capacity) { return; }
|
||||
|
||||
u64 index = (queue->back)++;
|
||||
_arraySet(queue->items, index, item, item_size);
|
||||
arraySet(queue->items, index, item, item_size);
|
||||
++(queue->count);
|
||||
|
||||
if (queue->back >= capacity) {
|
||||
@@ -22,7 +22,7 @@ void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
}
|
||||
}
|
||||
|
||||
WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *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,
|
||||
"`allocator`, `queue` and `item` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
@@ -35,7 +35,7 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
b8 queue_full = queue->count >= capacity;
|
||||
if (queue_full) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2);
|
||||
u64 array_size = _arrayCalcAllocSize(new_capacity, item_size);
|
||||
u64 array_size = arrayCalcAllocSize(new_capacity, item_size);
|
||||
u64 alloc_size = sizeof(WpQueue) + array_size;
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, alloc_size);
|
||||
if (!buffer) {
|
||||
@@ -45,7 +45,7 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
memset((void *)buffer, 0, alloc_size);
|
||||
|
||||
output = (WpQueue *)buffer;
|
||||
output->items = _arrayFromPreallocatedBuffer((void *)(output + 1), array_size, WP_ARRAY_INIT_FILLED, item_size);
|
||||
output->items = arrayFromPreallocatedBuffer((void *)(output + 1), array_size, WP_ARRAY_INIT_FILLED, item_size);
|
||||
|
||||
// NOTE (Abdelrahman): When the queue is full, the front and back indices should
|
||||
// always be the same
|
||||
@@ -84,13 +84,13 @@ WpQueue *_queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *ite
|
||||
output->count = queue->count;
|
||||
}
|
||||
|
||||
_queuePush(output, item, item_size);
|
||||
queuePush(output, item, item_size);
|
||||
|
||||
RETURN_QUEUE_PUSH_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
void *queuePop(WpQueue *queue, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
@@ -104,5 +104,5 @@ void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
queue->front = 0;
|
||||
}
|
||||
|
||||
return _arrayGet(queue->items, index, item_size);
|
||||
return arrayGet(queue->items, index, item_size);
|
||||
}
|
||||
|
||||
@@ -80,13 +80,13 @@ typedef WpQueue WpStr8Queue;
|
||||
#define wpQueueCapacity(QUEUE_PTR) (wpArrayCapacity((QUEUE_PTR)->items))
|
||||
#define wpQueueItemSize(QUEUE_PTR) (wpArrayItemSize((QUEUE_PTR)->items))
|
||||
#define wpQueuePush(TYPE, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
queuePush(QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueuePushAlloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR) ( \
|
||||
_queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
queuePushAlloc(ALLOCATOR_PTR, QUEUE_PTR, VALUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueuePop(TYPE, QUEUE_PTR) ( \
|
||||
(TYPE *)_queuePop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
(TYPE *)queuePop(QUEUE_PTR, sizeof(TYPE)) \
|
||||
)
|
||||
#define wpQueueDealloc(TYPE, ALLOCATOR_PTR, QUEUE_PTR) \
|
||||
(wpArrayDealloc(TYPE, ALLOCATOR_PTR, &((QUEUE_PTR)->items)), \
|
||||
@@ -94,9 +94,9 @@ typedef WpQueue WpStr8Queue;
|
||||
(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);
|
||||
void *_queuePop(WpQueue *queue, u64 item_size);
|
||||
void queuePush(WpQueue *queue, void *item, u64 item_size);
|
||||
WpQueue *queuePushAlloc(const WpAllocator *allocator, WpQueue *queue, void *item, u64 item_size);
|
||||
void *queuePop(WpQueue *queue, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -4,20 +4,20 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../common/assert/assert.h"
|
||||
|
||||
void _streamValidate(const WpStream *stream, u64 item_size);
|
||||
void streamValidate(const WpStream *stream, u64 item_size);
|
||||
|
||||
b8 wpStreamAtEnd(const WpStream *stream) {
|
||||
return stream->position >= stream->count;
|
||||
}
|
||||
|
||||
b8 _streamHasCount(const WpStream *stream, u64 count) {
|
||||
b8 streamHasCount(const WpStream *stream, u64 count) {
|
||||
return stream->position + count <= stream->count;
|
||||
}
|
||||
|
||||
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
void *streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, offset + 1)) {
|
||||
if (streamHasCount(stream, offset + 1)) {
|
||||
u64 index = (stream->position + offset) * stream->item_size;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
}
|
||||
@@ -25,10 +25,10 @@ void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
void *streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, count)) {
|
||||
if (streamHasCount(stream, count)) {
|
||||
u64 index = stream->position * stream->item_size;
|
||||
stream->position += count;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
@@ -37,7 +37,7 @@ void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void _streamValidate(const WpStream *stream, u64 item_size) {
|
||||
void streamValidate(const WpStream *stream, u64 item_size) {
|
||||
wpDebugAssert(stream != NULL, "`stream` should not be NULL");
|
||||
wpRuntimeAssert(stream->item_size == item_size, "Invalid item type provided");
|
||||
}
|
||||
|
||||
@@ -58,20 +58,20 @@ typedef WpStream WpStr8Stream;
|
||||
)
|
||||
#endif
|
||||
|
||||
#define wpStreamHasNext(STREAM) _streamHasCount(STREAM, 1)
|
||||
#define wpStreamHasCount(STREAM, COUNT) _streamHasCount(STREAM, COUNT)
|
||||
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)_streamPeekWithOffset(STREAM, 0, sizeof(TYPE)))
|
||||
#define wpStreamHasNext(STREAM) streamHasCount(STREAM, 1)
|
||||
#define wpStreamHasCount(STREAM, COUNT) streamHasCount(STREAM, COUNT)
|
||||
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)streamPeekWithOffset(STREAM, 0, sizeof(TYPE)))
|
||||
#define wpStreamPeekWithOffset(TYPE, STREAM, OFFSET) \
|
||||
((TYPE *)_streamPeekWithOffset(STREAM, OFFSET, sizeof(TYPE)))
|
||||
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)_streamConsumeCount(STREAM, 1, sizeof(TYPE)))
|
||||
((TYPE *)streamPeekWithOffset(STREAM, OFFSET, sizeof(TYPE)))
|
||||
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)streamConsumeCount(STREAM, 1, sizeof(TYPE)))
|
||||
#define wpStreamConsumeCount(TYPE, STREAM, COUNT) \
|
||||
((TYPE *)_streamConsumeCount(STREAM, COUNT, sizeof(TYPE)))
|
||||
((TYPE *)streamConsumeCount(STREAM, COUNT, sizeof(TYPE)))
|
||||
|
||||
b8 wpStreamAtEnd(const WpStream *stream);
|
||||
|
||||
b8 _streamHasCount(const WpStream *stream, u64 count);
|
||||
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size);
|
||||
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size);
|
||||
b8 streamHasCount(const WpStream *stream, u64 count);
|
||||
void *streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size);
|
||||
void *streamConsumeCount(WpStream *stream, u64 count, u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
@@ -115,6 +115,11 @@ void wpStr8Set(WpStr8 *str, u64 index, c8 c) {
|
||||
str->buf[index] = c;
|
||||
}
|
||||
|
||||
void wpStr8Clear(WpStr8 *str) {
|
||||
memset(str->buf, 0, str->capacity);
|
||||
str->size = 0;
|
||||
}
|
||||
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c) {
|
||||
if (!(str->size < str->capacity)) {
|
||||
return;
|
||||
|
||||
@@ -88,20 +88,21 @@ void wpStr8DeallocBuf(const WpAllocator *allocator, WpStr8 **str);
|
||||
/**
|
||||
* WpStr8 utilities
|
||||
*/
|
||||
c8 wpStr8Get(WpStr8RO *str, u64 index);
|
||||
void wpStr8Set(WpStr8 *str, u64 index, c8 c);
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c);
|
||||
b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2);
|
||||
b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count);
|
||||
c8 wpStr8Get(WpStr8RO *str, u64 index);
|
||||
void wpStr8Set(WpStr8 *str, u64 index, c8 c);
|
||||
void wpStr8Clear(WpStr8 *str);
|
||||
void wpStr8PushBack(WpStr8 *str, c8 c);
|
||||
b8 wpStr8Equal(WpStr8RO *s1, WpStr8RO *s2);
|
||||
b8 wpStr8EqualToCount(WpStr8RO* s1, WpStr8RO* s2, u64 count);
|
||||
WpStr8 wpStr8Slice(WpStr8RO *str, u64 start, u64 end);
|
||||
void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src);
|
||||
void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity);
|
||||
void wpStr8Format(WpStr8 *dst, const char *format, ...);
|
||||
void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src);
|
||||
void wpStr8ConcatCapped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyCstrCapped(WpStr8 *dst, const char *src);
|
||||
void wpStr8CopyStr8Capped(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8CopyToCstr(char *dst, WpStr8RO *src, u64 dst_capacity);
|
||||
void wpStr8Format(WpStr8 *dst, const char *format, ...);
|
||||
void wpStr8ToLower(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src);
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src);
|
||||
|
||||
/**
|
||||
* WpStr8 find functions
|
||||
|
||||
Reference in New Issue
Block a user