Rename array
This commit is contained in:
+77
-77
@@ -7,81 +7,81 @@
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define _array_header(ARRAY) (ArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(ArrayHeader) * -1))
|
||||
#define _array_header(ARRAY) (WpArrayHeader *)(wpMiscUtilsOffsetPointer(ARRAY, (i64)sizeof(WpArrayHeader) * -1))
|
||||
|
||||
wp_persist inline void _array_validate(const GenericArray array, u64 item_size);
|
||||
wp_persist inline void _array_validate(const WpArray array, u64 item_size);
|
||||
|
||||
u64 _array_count(GenericArray array) {
|
||||
u64 _arrayCount(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->count;
|
||||
}
|
||||
|
||||
u64 _array_capacity(GenericArray array) {
|
||||
u64 _arrayCapacity(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->capacity;
|
||||
}
|
||||
|
||||
u64 _array_item_size(GenericArray array) {
|
||||
u64 _arrayItemSize(WpArray array) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
return header->item_size;
|
||||
}
|
||||
|
||||
void _array_set_count(GenericArray array, u64 count) {
|
||||
void _arraySetCount(WpArray array, u64 count) {
|
||||
wpDebugAssert(array != NULL, "`array` should not be NULL");
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
|
||||
header->count = count;
|
||||
}
|
||||
|
||||
void *_array_get(GenericArray array, u64 index, u64 item_size) {
|
||||
void *_arrayGet(WpArray array, u64 index, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_array_validate(array, item_size);
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(index < header->count, "`index` is out of bounds");
|
||||
|
||||
return wpMiscUtilsOffsetPointer(array, header->item_size * index);
|
||||
}
|
||||
|
||||
void _array_set(GenericArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _array_get(array, index, item_size);
|
||||
void _arraySet(WpArray array, u64 index, void *value, u64 item_size) {
|
||||
void *item = _arrayGet(array, index, item_size);
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
memcpy(item, value, header->item_size);
|
||||
}
|
||||
|
||||
void _array_append_capped(GenericArray array, void *value, u64 item_size) {
|
||||
void _arrayAppendCapped(WpArray array, void *value, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_array_validate(array, item_size);
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
if (header->count >= header->capacity) { return; }
|
||||
|
||||
u64 index = (header->count)++;
|
||||
_array_set(array, index, value, item_size);
|
||||
_arraySet(array, index, value, item_size);
|
||||
}
|
||||
|
||||
void _array_extend_capped(GenericArray dst, const GenericArray 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");
|
||||
_array_validate(dst, item_size);
|
||||
_array_validate(src, item_size);
|
||||
|
||||
ArrayHeader *src_header = _array_header(src);
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
WpArrayHeader *src_header = _array_header(src);
|
||||
WpArrayHeader *dst_header = _array_header(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 _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_siz
|
||||
dst_header->count += copy_count;
|
||||
}
|
||||
|
||||
void _array_copy_capped(GenericArray dst, const GenericArray 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");
|
||||
_array_validate(dst, item_size);
|
||||
_array_validate(src, item_size);
|
||||
|
||||
_array_clear(dst, item_size);
|
||||
_arrayClear(dst, item_size);
|
||||
|
||||
ArrayHeader *src_header = _array_header(src);
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
WpArrayHeader *src_header = _array_header(src);
|
||||
WpArrayHeader *dst_header = _array_header(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;
|
||||
}
|
||||
|
||||
GenericArray _array_append_alloc(const WpAllocator *allocator, GenericArray array, void *value,
|
||||
ArrayInitFlags flags, u64 item_size) {
|
||||
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");
|
||||
_array_validate(array, item_size);
|
||||
|
||||
GenericArray output = array;
|
||||
WpArray output = array;
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
if (header->count >= header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(header->capacity * 2);
|
||||
output = (GenericArray )_array_alloc_capacity(allocator, new_capacity, flags,
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity, flags,
|
||||
header->item_size);
|
||||
if (!output) {
|
||||
output = array;
|
||||
goto RETURN_ARRAY_APPEND_ALLOC;
|
||||
}
|
||||
_array_copy_capped(output, array, item_size);
|
||||
_arrayCopyCapped(output, array, item_size);
|
||||
}
|
||||
|
||||
_array_append_capped(output, value, item_size);
|
||||
_arrayAppendCapped(output, value, item_size);
|
||||
|
||||
if ((flags & ARRAY_INIT_FILLED) == ARRAY_INIT_FILLED) {
|
||||
_array_set_count(output, _array_capacity(output));
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_APPEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
GenericArray _array_extend_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size) {
|
||||
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");
|
||||
_array_validate(dst, item_size);
|
||||
_array_validate(src, item_size);
|
||||
|
||||
GenericArray output = dst;
|
||||
WpArray output = dst;
|
||||
|
||||
ArrayHeader *src_header = _array_header(src);
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
WpArrayHeader *src_header = _array_header(src);
|
||||
WpArrayHeader *dst_header = _array_header(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 = (GenericArray )_array_alloc_capacity(allocator, new_capacity,
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, dst_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
goto RETURN_ARRAY_EXTEND_ALLOC;
|
||||
}
|
||||
_array_copy_capped(output, dst, item_size);
|
||||
_arrayCopyCapped(output, dst, item_size);
|
||||
}
|
||||
|
||||
_array_extend_capped(output, src, item_size);
|
||||
_arrayExtendCappend(output, src, item_size);
|
||||
|
||||
if ((flags & ARRAY_INIT_FILLED) == ARRAY_INIT_FILLED) {
|
||||
_array_set_count(output, _array_capacity(output));
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_EXTEND_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
GenericArray _array_copy_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size) {
|
||||
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");
|
||||
_array_validate(dst, item_size);
|
||||
_array_validate(src, item_size);
|
||||
|
||||
GenericArray output = dst;
|
||||
WpArray output = dst;
|
||||
|
||||
ArrayHeader *src_header = _array_header(src);
|
||||
ArrayHeader *dst_header = _array_header(dst);
|
||||
WpArrayHeader *src_header = _array_header(src);
|
||||
WpArrayHeader *dst_header = _array_header(dst);
|
||||
if (src_header->count >= dst_header->capacity) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(dst_header->capacity * 2);
|
||||
output = (GenericArray )_array_alloc_capacity(allocator, new_capacity,
|
||||
output = (WpArray )_arrayAllocCapacity(allocator, new_capacity,
|
||||
flags, src_header->item_size);
|
||||
if (!output) {
|
||||
output = dst;
|
||||
@@ -185,82 +185,82 @@ GenericArray _array_copy_alloc(const WpAllocator *allocator, GenericArray dst, c
|
||||
}
|
||||
}
|
||||
|
||||
_array_copy_capped(output, src, item_size);
|
||||
_arrayCopyCapped(output, src, item_size);
|
||||
|
||||
if ((flags & ARRAY_INIT_FILLED) == ARRAY_INIT_FILLED) {
|
||||
_array_set_count(output, _array_capacity(output));
|
||||
if ((flags & WP_ARRAY_INIT_FILLED) == WP_ARRAY_INIT_FILLED) {
|
||||
_arraySetCount(output, _arrayCapacity(output));
|
||||
}
|
||||
|
||||
RETURN_ARRAY_COPY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
void *_array_pop(GenericArray array, u64 item_size) {
|
||||
void *_arrayPop(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_array_validate(array, item_size);
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
if (header->count == 0) { return NULL; }
|
||||
|
||||
u64 index = header->count - 1;
|
||||
void *out = _array_get(array, index, item_size);
|
||||
void *out = _arrayGet(array, index, item_size);
|
||||
--(header->count);
|
||||
return out;
|
||||
}
|
||||
|
||||
void _array_clear(GenericArray array, u64 item_size) {
|
||||
void _arrayClear(WpArray array, u64 item_size) {
|
||||
wpRuntimeAssert(array != NULL, "`array` should not be NULL");
|
||||
_array_validate(array, item_size);
|
||||
|
||||
ArrayHeader *header = _array_header(array);
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
header->count = 0;
|
||||
}
|
||||
|
||||
u64 _array_calc_alloc_size(u64 capacity, u64 item_size) {
|
||||
return sizeof(ArrayHeader) + item_size * capacity;
|
||||
u64 _arrayCalcAllocSize(u64 capacity, u64 item_size) {
|
||||
return sizeof(WpArrayHeader) + item_size * capacity;
|
||||
}
|
||||
|
||||
GenericArray _array_alloc_capacity(const WpAllocator *allocator, u64 capacity, ArrayInitFlags flags,
|
||||
WpArray _arrayAllocCapacity(const WpAllocator *allocator, u64 capacity, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
GenericArray output = NULL;
|
||||
WpArray output = NULL;
|
||||
|
||||
u64 allocation_size = _array_calc_alloc_size(capacity, item_size);
|
||||
u64 allocation_size = _arrayCalcAllocSize(capacity, item_size);
|
||||
void *buffer = wpMemAllocatorAlloc(allocator, allocation_size);
|
||||
if (!buffer) {
|
||||
goto RETURN_ARRAY_ALLOC;
|
||||
}
|
||||
|
||||
output = _array_from_preallocated_buffer(buffer, allocation_size, flags, item_size);
|
||||
output = _arrayFromPreallocatedBuffer(buffer, allocation_size, flags, item_size);
|
||||
|
||||
RETURN_ARRAY_ALLOC:
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, ArrayInitFlags flags,
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size) {
|
||||
wpRuntimeAssert(buffer != NULL, "`buffer` should not be NULL");
|
||||
|
||||
i64 data_buffer_size = (i64)buffer_size - (i64)(sizeof(ArrayHeader));
|
||||
i64 data_buffer_size = (i64)buffer_size - (i64)(sizeof(WpArrayHeader));
|
||||
if (data_buffer_size <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u64 item_capacity = (u64)data_buffer_size / item_size;
|
||||
ArrayHeader *header = (ArrayHeader *)buffer;
|
||||
GenericArray output = (u8 *)(header + 1);
|
||||
header->magic = WAPP_ARRAY_MAGIC;
|
||||
header->count = flags & ARRAY_INIT_FILLED ? item_capacity : 0;
|
||||
WpArrayHeader *header = (WpArrayHeader *)buffer;
|
||||
WpArray output = (u8 *)(header + 1);
|
||||
header->magic = WP_ARRAY_MAGIC;
|
||||
header->count = flags & WP_ARRAY_INIT_FILLED ? item_capacity : 0;
|
||||
header->capacity = item_capacity;
|
||||
header->item_size = item_size;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
wp_persist inline void _array_validate(const GenericArray array, u64 item_size) {
|
||||
ArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WAPP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
wp_persist inline void _array_validate(const WpArray array, u64 item_size) {
|
||||
WpArrayHeader *header = _array_header(array);
|
||||
wpRuntimeAssert(WP_ARRAY_MAGIC == header->magic, "`array` is not a valid wapp array");
|
||||
wpRuntimeAssert(item_size == header->item_size, "Invalid item type provided");
|
||||
}
|
||||
|
||||
+119
-119
@@ -12,202 +12,202 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define WAPP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
#define WP_ARRAY_MAGIC (u64)0x57415f415252
|
||||
|
||||
#define _calc_array_count(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calc_array_capacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calc_array_count(TYPE, __VA_ARGS__) * 2)
|
||||
#define _calcArrayCount(TYPE, ...) wpMiscUtilsVaArgsCount(TYPE, __VA_ARGS__)
|
||||
#define _calcArrayCapacity(TYPE, ...) wpMiscUtilsU64RoundUpPow2(_calcArrayCount(TYPE, __VA_ARGS__) * 2)
|
||||
|
||||
typedef struct WpStr8 WpStr8;
|
||||
|
||||
// NOTE (Abdelrahman): Typedefs to distinguish arrays from regular pointers
|
||||
typedef void *GenericArray;
|
||||
typedef void **VoidPtrArray;
|
||||
typedef c8 *C8Array;
|
||||
typedef c16 *C16Array;
|
||||
typedef c32 *C32Array;
|
||||
typedef u8 *U8Array;
|
||||
typedef u16 *U16Array;
|
||||
typedef u32 *U32Array;
|
||||
typedef u64 *U64Array;
|
||||
typedef b8 *B8Array;
|
||||
typedef i8 *I8Array;
|
||||
typedef i16 *I16Array;
|
||||
typedef i32 *I32Array;
|
||||
typedef i64 *I64Array;
|
||||
typedef f32 *F32Array;
|
||||
typedef f64 *F64Array;
|
||||
typedef f128 *F128Array;
|
||||
typedef uptr *UptrArray;
|
||||
typedef iptr *IptrArray;
|
||||
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 {
|
||||
ARRAY_INIT_NONE = 0,
|
||||
ARRAY_INIT_FILLED = 1 << 1,
|
||||
} ArrayInitFlags;
|
||||
WP_ARRAY_INIT_NONE = 0,
|
||||
WP_ARRAY_INIT_FILLED = 1 << 1,
|
||||
} WpArrayInitFlags;
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wapp_array(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calc_array_capacity(TYPE, __VA_ARGS__); \
|
||||
#define wpArray(TYPE, ...) ([&]() { \
|
||||
u64 capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
\
|
||||
TYPE items[_calc_array_capacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
TYPE items[_calcArrayCapacity(TYPE, __VA_ARGS__)] = {__VA_ARGS__}; \
|
||||
\
|
||||
wp_persist u8 array[ \
|
||||
sizeof(ArrayHeader) + _calc_array_capacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + _calcArrayCapacity(TYPE, __VA_ARGS__) * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
ArrayHeader *header = (ArrayHeader *)array; \
|
||||
header->magic = WAPP_ARRAY_MAGIC; \
|
||||
header->count = _calc_array_count(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calc_array_capacity(TYPE, __VA_ARGS__); \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = _calcArrayCount(TYPE, __VA_ARGS__); \
|
||||
header->capacity = _calcArrayCapacity(TYPE, __VA_ARGS__); \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
u8 *buf = (u8 *)(header + 1); \
|
||||
memcpy(buf, items, capacity * sizeof(TYPE)); \
|
||||
return (TYPE *)buf; \
|
||||
}())
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) ([&]() { \
|
||||
wp_persist u8 array[ \
|
||||
sizeof(ArrayHeader) + CAPACITY * sizeof(TYPE) \
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) ([&]() { \
|
||||
wp_persist u8 array[ \
|
||||
sizeof(WpArrayHeader) + CAPACITY * sizeof(TYPE) \
|
||||
] = {0}; \
|
||||
ArrayHeader *header = (ArrayHeader *)array; \
|
||||
header->magic = WAPP_ARRAY_MAGIC; \
|
||||
header->count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0; \
|
||||
WpArrayHeader *header = (WpArrayHeader *)array; \
|
||||
header->magic = WP_ARRAY_MAGIC; \
|
||||
header->count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0; \
|
||||
header->capacity = CAPACITY; \
|
||||
header->item_size = sizeof(TYPE); \
|
||||
\
|
||||
return (TYPE *)(header + 1); \
|
||||
}())
|
||||
#define wapp_array_pop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _array_count((GenericArray)ARRAY) == 0) { \
|
||||
#define wpArrayPop(TYPE, ARRAY) ([&]() { \
|
||||
if (ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0) { \
|
||||
TYPE result{}; \
|
||||
return result; \
|
||||
} \
|
||||
\
|
||||
return *((TYPE *)_array_pop((GenericArray)ARRAY, sizeof(TYPE))); \
|
||||
return *((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))); \
|
||||
}())
|
||||
#else
|
||||
#define _stack_array(TYPE, SIZE) struct {ArrayHeader header; \
|
||||
#define _stackArray(TYPE, SIZE) struct {WpArrayHeader header; \
|
||||
TYPE items[SIZE]; \
|
||||
wpMiscUtilsReservePadding(sizeof(ArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wapp_array(TYPE, ...) \
|
||||
wpMiscUtilsReservePadding(sizeof(WpArrayHeader) + \
|
||||
sizeof(TYPE) * SIZE);}
|
||||
#define wpArray(TYPE, ...) \
|
||||
((TYPE *)( \
|
||||
(_stack_array(TYPE, _calc_array_capacity(TYPE, __VA_ARGS__))){ \
|
||||
(_stackArray(TYPE, _calcArrayCapacity(TYPE, __VA_ARGS__))){ \
|
||||
.header = { \
|
||||
.magic = WAPP_ARRAY_MAGIC, \
|
||||
.count = _calc_array_count(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calc_array_capacity(TYPE, __VA_ARGS__), \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = _calcArrayCount(TYPE, __VA_ARGS__), \
|
||||
.capacity = _calcArrayCapacity(TYPE, __VA_ARGS__), \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {__VA_ARGS__}, \
|
||||
}.items \
|
||||
))
|
||||
#define wapp_array_with_capacity(TYPE, CAPACITY, FLAGS) \
|
||||
#define wpArrayWithCapacity(TYPE, CAPACITY, FLAGS) \
|
||||
((TYPE *)( \
|
||||
(_stack_array(TYPE, CAPACITY)){ \
|
||||
(_stackArray(TYPE, CAPACITY)){ \
|
||||
.header = { \
|
||||
.magic = WAPP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
.magic = WP_ARRAY_MAGIC, \
|
||||
.count = (FLAGS & WP_ARRAY_INIT_FILLED) ? CAPACITY : 0, \
|
||||
.capacity = CAPACITY, \
|
||||
.item_size = sizeof(TYPE), \
|
||||
}, \
|
||||
.items = {0}, \
|
||||
}.items \
|
||||
))
|
||||
#define wapp_array_pop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _array_count((GenericArray)ARRAY) == 0 ? \
|
||||
#define wpArrayPop(TYPE, ARRAY) \
|
||||
(ARRAY == NULL || _arrayCount((WpArray)ARRAY) == 0 ? \
|
||||
(TYPE){0} : \
|
||||
*((TYPE *)_array_pop((GenericArray)ARRAY, sizeof(TYPE))) \
|
||||
*((TYPE *)_arrayPop((WpArray)ARRAY, sizeof(TYPE))) \
|
||||
)
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wapp_array_count(ARRAY) \
|
||||
(_array_count((GenericArray)ARRAY))
|
||||
#define wapp_array_capacity(ARRAY) \
|
||||
(_array_capacity((GenericArray)ARRAY))
|
||||
#define wapp_array_item_size(ARRAY) \
|
||||
(_array_item_size((GenericArray)ARRAY))
|
||||
#define wapp_array_set_count(ARRAY, COUNT) \
|
||||
(_array_set_count((GenericArray)ARRAY, COUNT))
|
||||
#define wapp_array_get(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_array_get((GenericArray)ARRAY, \
|
||||
#define wpArrayCount(ARRAY) \
|
||||
(_arrayCount((WpArray)ARRAY))
|
||||
#define wpArrayCapacity(ARRAY) \
|
||||
(_arrayCapacity((WpArray)ARRAY))
|
||||
#define wpArrayItemSize(ARRAY) \
|
||||
(_arrayItemSize((WpArray)ARRAY))
|
||||
#define wpArraySetCount(ARRAY, COUNT) \
|
||||
(_arraySetCount((WpArray)ARRAY, COUNT))
|
||||
#define wpArrayGet(TYPE, ARRAY, INDEX) \
|
||||
((TYPE *)_arrayGet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_set(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_array_set((GenericArray)ARRAY, \
|
||||
#define wpArraySet(TYPE, ARRAY, INDEX, VALUE_PTR) \
|
||||
(_arraySet((WpArray)ARRAY, \
|
||||
INDEX, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_append_capped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_array_append_capped((GenericArray)ARRAY, \
|
||||
#define wpArrayAppendCapped(TYPE, ARRAY, VALUE_PTR) \
|
||||
(_arrayAppendCapped((WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_extend_capped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_array_extend_capped((GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayExtendCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayExtendCappend((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_copy_capped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_array_copy_capped((GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayCopyCapped(TYPE, DST_ARRAY, SRC_ARRAY) \
|
||||
(_arrayCopyCapped((WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_append_alloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_array_append_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)ARRAY, \
|
||||
#define wpArrayAppendAlloc(TYPE, ALLOCATOR_PTR, ARRAY, VALUE_PTR, FLAGS) \
|
||||
((TYPE *)_arrayAppendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)ARRAY, \
|
||||
(u8 *)VALUE_PTR, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_extend_alloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_array_extend_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayExtendAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayExtendAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_copy_alloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_array_copy_alloc(ALLOCATOR_PTR, \
|
||||
(GenericArray)DST_ARRAY, \
|
||||
(GenericArray)SRC_ARRAY, \
|
||||
#define wpArrayCopyAlloc(TYPE, ALLOCATOR_PTR, DST_ARRAY, SRC_ARRAY, FLAGS) \
|
||||
((TYPE *)_arrayCopyAlloc(ALLOCATOR_PTR, \
|
||||
(WpArray)DST_ARRAY, \
|
||||
(WpArray)SRC_ARRAY, \
|
||||
FLAGS, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_clear(TYPE, ARRAY) \
|
||||
(_array_clear((GenericArray)ARRAY, \
|
||||
#define wpArrayClear(TYPE, ARRAY) \
|
||||
(_arrayClear((WpArray)ARRAY, \
|
||||
sizeof(TYPE)))
|
||||
#define wapp_array_calc_alloc_size(TYPE, CAPACITY) _array_calc_alloc_size(CAPACITY, sizeof(TYPE))
|
||||
#define wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_array_alloc_capacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wapp_array_from_preallcated_buffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
#define wpArrayCalcAllocSize(TYPE, CAPACITY) _arrayCalcAllocSize(CAPACITY, sizeof(TYPE))
|
||||
#define wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, FLAGS) \
|
||||
((TYPE *)_arrayAllocCapacity(ALLOCATOR_PTR, CAPACITY, FLAGS, sizeof(TYPE)))
|
||||
#define wpArrayFromPreallcatedBuffer(TYPE, BUFFER, BUFFER_SIZE) \
|
||||
((TYPE *)_array_from_preallcated_buffer(BUFFER, BUFFER_SIZE, sizeof(TYPE)))
|
||||
|
||||
|
||||
typedef struct header ArrayHeader;
|
||||
struct header {
|
||||
typedef struct WpArrayHeader WpArrayHeader;
|
||||
struct WpArrayHeader {
|
||||
u64 magic;
|
||||
u64 count;
|
||||
u64 capacity;
|
||||
u64 item_size;
|
||||
};
|
||||
|
||||
u64 _array_count(GenericArray array);
|
||||
u64 _array_capacity(GenericArray array);
|
||||
u64 _array_item_size(GenericArray array);
|
||||
void _array_set_count(GenericArray array, u64 count);
|
||||
void *_array_get(GenericArray array, u64 index, u64 item_size);
|
||||
void _array_set(GenericArray array, u64 index, void *value, u64 item_size);
|
||||
void _array_append_capped(GenericArray array, void *value, u64 item_size);
|
||||
void _array_extend_capped(GenericArray dst, const GenericArray src, u64 item_size);
|
||||
void _array_copy_capped(GenericArray dst, const GenericArray src, u64 item_size);
|
||||
GenericArray _array_append_alloc(const WpAllocator *allocator, GenericArray array, void *value,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
GenericArray _array_extend_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
GenericArray _array_copy_alloc(const WpAllocator *allocator, GenericArray dst, const GenericArray src,
|
||||
ArrayInitFlags flags, u64 item_size);
|
||||
void *_array_pop(GenericArray array, u64 item_size);
|
||||
void _array_clear(GenericArray array, u64 item_size);
|
||||
u64 _array_calc_alloc_size(u64 capacity, u64 item_size);
|
||||
GenericArray _array_alloc_capacity(const WpAllocator *allocator, u64 capacity, ArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
GenericArray _array_from_preallocated_buffer(void *buffer, u64 buffer_size, ArrayInitFlags flags,
|
||||
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,
|
||||
WpArrayInitFlags flags, u64 item_size);
|
||||
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,
|
||||
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,
|
||||
u64 item_size);
|
||||
WpArray _arrayFromPreallocatedBuffer(void *buffer, u64 buffer_size, WpArrayInitFlags flags,
|
||||
u64 item_size);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
+10
-10
@@ -8,13 +8,13 @@
|
||||
|
||||
void _queuePush(WpQueue *queue, void *item, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
if (queue->count >= capacity) { return; }
|
||||
|
||||
u64 index = (queue->back)++;
|
||||
_array_set(queue->items, index, item, item_size);
|
||||
_arraySet(queue->items, index, item, item_size);
|
||||
++(queue->count);
|
||||
|
||||
if (queue->back >= capacity) {
|
||||
@@ -25,17 +25,17 @@ void _queuePush(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 == wapp_array_item_size(queue->items), "Invalid type");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
WpQueue *output = queue;
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
|
||||
// NOTE (Abdelrahman): Extracted into variable to fix MSVC error
|
||||
b8 queue_full = queue->count >= capacity;
|
||||
if (queue_full) {
|
||||
u64 new_capacity = wpMiscUtilsU64RoundUpPow2(capacity * 2);
|
||||
u64 array_size = _array_calc_alloc_size(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 = _array_from_preallocated_buffer((void *)(output + 1), array_size, 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
|
||||
@@ -92,17 +92,17 @@ RETURN_QUEUE_PUSH_ALLOC:
|
||||
|
||||
void *_queuePop(WpQueue *queue, u64 item_size) {
|
||||
wpDebugAssert(queue != NULL, "`queue` should not be NULL");
|
||||
wpRuntimeAssert(item_size == wapp_array_item_size(queue->items), "Invalid type");
|
||||
wpRuntimeAssert(item_size == wpArrayItemSize(queue->items), "Invalid type");
|
||||
|
||||
if (queue->count == 0) { return NULL; }
|
||||
|
||||
u64 index = (queue->front)++;
|
||||
--(queue->count);
|
||||
|
||||
u64 capacity = wapp_array_capacity(queue->items);
|
||||
u64 capacity = wpArrayCapacity(queue->items);
|
||||
if (queue->front >= capacity) {
|
||||
queue->front = 0;
|
||||
}
|
||||
|
||||
return _array_get(queue->items, index, item_size);
|
||||
return _arrayGet(queue->items, index, item_size);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
typedef struct {
|
||||
GenericArray items;
|
||||
WpArray items;
|
||||
u64 front;
|
||||
u64 back;
|
||||
u64 count;
|
||||
@@ -42,7 +42,7 @@ typedef WpQueue WpStr8Queue;
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
#define wpQueue(TYPE, CAPACITY) ([&]() { \
|
||||
wp_persist GenericArray arr = wapp_array_with_capacity(TYPE, CAPACITY, 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 = { \
|
||||
wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
||||
wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
@@ -64,21 +64,21 @@ typedef WpQueue WpStr8Queue;
|
||||
}())
|
||||
#else
|
||||
#define wpQueue(TYPE, CAPACITY) ((WpQueue){ \
|
||||
.items = wapp_array_with_capacity(TYPE, CAPACITY, 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 = wapp_array_alloc_capacity(TYPE, ALLOCATOR_PTR, CAPACITY, ARRAY_INIT_FILLED), \
|
||||
.items = wpArrayAllocCapacity(TYPE, ALLOCATOR_PTR, CAPACITY, WP_ARRAY_INIT_FILLED), \
|
||||
.front = 0, \
|
||||
.back = 0, \
|
||||
.count = 0, \
|
||||
})
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#define wpQueueCapacity(QUEUE_PTR) (wapp_array_capacity((QUEUE_PTR)->items))
|
||||
#define wpQueueItemSize(QUEUE_PTR) (wapp_array_item_size((QUEUE_PTR)->items))
|
||||
#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)) \
|
||||
)
|
||||
|
||||
@@ -275,10 +275,10 @@ void wpStr8ToUpper(WpStr8 *dst, WpStr8RO *src) {
|
||||
}
|
||||
}
|
||||
|
||||
void wpStr8FromBytes(WpStr8 *dst, const U8Array src) {
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src) {
|
||||
wpDebugAssert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL");
|
||||
|
||||
u64 size = wapp_array_count(src) * wapp_array_item_size(src);
|
||||
u64 size = wpArrayCount(src) * wpArrayItemSize(src);
|
||||
|
||||
wpDebugAssert(dst->capacity >= size, "`dst` does not have enough capacity");
|
||||
|
||||
@@ -333,12 +333,12 @@ i64 wpStr8Rfind(WpStr8RO *str, WpStr8RO substr) {
|
||||
WpStr8List *wpStr8SplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) {
|
||||
wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator);
|
||||
WpStr8List *output = wpDblListAlloc(WpStr8, allocator);
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
WpStr8 *full = wpStr8AllocStr8(allocator, str);
|
||||
if (full) {
|
||||
wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, full);
|
||||
wpDblListPush_back_alloc(WpStr8, allocator, output, full);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -357,7 +357,7 @@ WpStr8List *wpStr8SplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpSt
|
||||
|
||||
before_str = wpStr8AllocSubstr(allocator, str, start, start + end);
|
||||
if (before_str) {
|
||||
wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, before_str);
|
||||
wpDblListPush_back_alloc(WpStr8, allocator, output, before_str);
|
||||
}
|
||||
|
||||
wpMemAllocatorFree(allocator, (void **)&rest, sizeof(WpStr8));
|
||||
@@ -370,7 +370,7 @@ WpStr8List *wpStr8SplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpSt
|
||||
// Ensure the last part of the string after the delimiter is added to the list
|
||||
rest = wpStr8AllocSubstr(allocator, str, start, str->size);
|
||||
if (rest) {
|
||||
wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, rest);
|
||||
wpDblListPush_back_alloc(WpStr8, allocator, output, rest);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
@@ -380,12 +380,12 @@ RETURN_STR8_SPLIT:
|
||||
WpStr8List *wpStr8RsplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpStr8RO *delimiter, i64 max_splits) {
|
||||
wpDebugAssert(allocator != NULL && str != NULL && delimiter != NULL, "`allocator`, `str` and `delimiter` should not be NULL");
|
||||
|
||||
WpStr8List *output = wapp_dbl_list_alloc(WpStr8, allocator);
|
||||
WpStr8List *output = wpDblListAlloc(WpStr8, allocator);
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
WpStr8 *full = wpStr8AllocStr8(allocator, str);
|
||||
if (full) {
|
||||
wapp_dbl_list_push_back_alloc(WpStr8, allocator, output, full);
|
||||
wpDblListPush_back_alloc(WpStr8, allocator, output, full);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -403,7 +403,7 @@ WpStr8List *wpStr8RsplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpS
|
||||
|
||||
after_str = wpStr8AllocSubstr(allocator, rest, end + delimiter->size, str->size);
|
||||
if (after_str) {
|
||||
wapp_dbl_list_push_front_alloc(WpStr8, allocator, output, after_str);
|
||||
wpDblListPush_front_alloc(WpStr8, allocator, output, after_str);
|
||||
}
|
||||
|
||||
wpMemAllocatorFree(allocator, (void **)&rest, sizeof(WpStr8));
|
||||
@@ -414,7 +414,7 @@ WpStr8List *wpStr8RsplitWithMax(const WpAllocator *allocator, WpStr8RO *str, WpS
|
||||
|
||||
rest = wpStr8AllocSubstr(allocator, str, 0, rest->size);
|
||||
if (rest) {
|
||||
wapp_dbl_list_push_front_alloc(WpStr8, allocator, output, rest);
|
||||
wpDblListPush_front_alloc(WpStr8, allocator, output, rest);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
@@ -433,7 +433,7 @@ WpStr8 *wpStr8Join(const WpAllocator *allocator, const WpStr8List *list, WpStr8R
|
||||
u64 node_index = 0;
|
||||
b8 running = node_index < list->node_count;
|
||||
while (running) {
|
||||
node = wapp_dbl_list_get(WpStr8, list, node_index);
|
||||
node = wpDblListGet(WpStr8, list, node_index);
|
||||
if (!node) {
|
||||
break;
|
||||
}
|
||||
@@ -466,7 +466,7 @@ u64 wpStr8ListTotalSize(const WpStr8List *list) {
|
||||
u64 output = 0;
|
||||
b8 running = node_index < list->node_count;
|
||||
while (running) {
|
||||
node = wapp_dbl_list_get(WpStr8, list, node_index);
|
||||
node = wpDblListGet(WpStr8, list, node_index);
|
||||
if (!node) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ 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 U8Array src);
|
||||
void wpStr8FromBytes(WpStr8 *dst, const WpU8Array src);
|
||||
|
||||
/**
|
||||
* WpStr8 find functions
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
WpTestFuncResult test_i32_array(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wapp_array_count(array) == 7 && wapp_array_capacity(array) == 16;
|
||||
WpI32Array array = wpArray(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wpArrayCount(array) == 7 && wpArrayCapacity(array) == 16;
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)(index + 1);
|
||||
|
||||
++index;
|
||||
@@ -25,11 +25,11 @@ WpTestFuncResult test_i32_array(void) {
|
||||
WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array1) == 0 && wapp_array_capacity(array1) == 64;
|
||||
WpI32Array array1 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array1) == 0 && wpArrayCapacity(array1) == 64;
|
||||
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_FILLED);
|
||||
result = wapp_array_count(array2) == 64 && wapp_array_capacity(array2) == 64;
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_FILLED);
|
||||
result = wpArrayCount(array2) == 64 && wpArrayCapacity(array2) == 64;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -37,14 +37,14 @@ WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_get(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)index;
|
||||
|
||||
++index;
|
||||
@@ -57,16 +57,16 @@ WpTestFuncResult test_i32_array_get(void) {
|
||||
WpTestFuncResult test_i32_array_set(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)(index * 2);
|
||||
wapp_array_set(i32, array, index, &num);
|
||||
item = wapp_array_get(i32, array, index);
|
||||
wpArraySet(i32, array, index, &num);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && *item == (i32)(index * 2);
|
||||
|
||||
++index;
|
||||
@@ -79,17 +79,17 @@ WpTestFuncResult test_i32_array_set(void) {
|
||||
WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
WpI32Array array = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
wpArrayAppendCapped(i32, array, &((i32){10}));
|
||||
|
||||
result = wapp_array_count(array) == 1;
|
||||
i32 *item = wapp_array_get(i32, array, 0);
|
||||
result = wpArrayCount(array) == 1;
|
||||
i32 *item = wpArrayGet(i32, array, 0);
|
||||
result = result && item && *item == 10;
|
||||
|
||||
array = wapp_array(i32, 1);
|
||||
wapp_array_append_capped(i32, array, &((i32){10}));
|
||||
array = wpArray(i32, 1);
|
||||
wpArrayAppendCapped(i32, array, &((i32){10}));
|
||||
|
||||
result = result && wapp_array_count(array) == 2;
|
||||
result = result && wpArrayCount(array) == 2;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -97,14 +97,14 @@ WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4);
|
||||
I32Array array2 = wapp_array(i32, 10, 20);
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4);
|
||||
WpI32Array array2 = wpArray(i32, 10, 20);
|
||||
|
||||
result = wapp_array_count(array1) == 4 && wapp_array_count(array2) == 2;
|
||||
result = wpArrayCount(array1) == 4 && wpArrayCount(array2) == 2;
|
||||
|
||||
wapp_array_extend_capped(i32, array1, array2);
|
||||
wpArrayExtendCapped(i32, array1, array2);
|
||||
|
||||
result = result && wapp_array_count(array1) == 6;
|
||||
result = result && wpArrayCount(array1) == 6;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -112,31 +112,31 @@ WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
|
||||
u64 expected_count = 5;
|
||||
wapp_array_copy_capped(i32, dst1, src);
|
||||
result = wapp_array_count(dst1) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst1, src);
|
||||
result = wpArrayCount(dst1) == expected_count;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst1, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst1, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 4;
|
||||
wapp_array_copy_capped(i32, dst2, src);
|
||||
result = result && wapp_array_count(dst2) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst2, src);
|
||||
result = result && wpArrayCount(dst2) == expected_count;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst2, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst2, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
@@ -148,13 +148,13 @@ WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
u64 capacity = 32;
|
||||
I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayAllocCapacity(i32, &allocator, capacity, WP_ARRAY_INIT_NONE);
|
||||
|
||||
result = array && wapp_array_capacity(array) == capacity;
|
||||
result = array && wpArrayCapacity(array) == capacity;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -162,11 +162,11 @@ WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
|
||||
I32Array arr_ptr = wapp_array_append_alloc(i32, &allocator, array1, &((i32){10}), ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayAppendAlloc(i32, &allocator, array1, &((i32){10}), WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
u64 count = 4;
|
||||
@@ -174,14 +174,14 @@ WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)index;
|
||||
arr_ptr = wapp_array_append_alloc(i32, &allocator, array2, &num, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayAppendAlloc(i32, &allocator, array2, &num, WP_ARRAY_INIT_NONE);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -189,18 +189,18 @@ WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
I32Array array3 = wapp_array(i32, 1, 2, 3, 4);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array3 = wpArray(i32, 1, 2, 3, 4);
|
||||
|
||||
I32Array arr_ptr = wapp_array_extend_alloc(i32, &allocator, array1, array3, ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayExtendAlloc(i32, &allocator, array1, array3, WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
arr_ptr = wapp_array_extend_alloc(i32, &allocator, array2, array3, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayExtendAlloc(i32, &allocator, array2, array3, WP_ARRAY_INIT_NONE);
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -208,39 +208,39 @@ WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
I32Array array = NULL;
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array = NULL;
|
||||
|
||||
u64 expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst1, src, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array) == expected_count && array == dst1;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst1, src, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array) == expected_count && array == dst1;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst2, src, ARRAY_INIT_NONE);
|
||||
result = result && wapp_array_count(array) == expected_count && array != dst2;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst2, src, WP_ARRAY_INIT_NONE);
|
||||
result = result && wpArrayCount(array) == expected_count && array != dst2;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && *wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index);
|
||||
result = result && *wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index);
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -248,11 +248,11 @@ WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_pop(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 32, ARRAY_INIT_NONE);
|
||||
WpI32Array array1 = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 32, WP_ARRAY_INIT_NONE);
|
||||
|
||||
i32 item1 = wapp_array_pop(i32, array1);
|
||||
i32 item2 = wapp_array_pop(i32, array2);
|
||||
i32 item1 = wpArrayPop(i32, array1);
|
||||
i32 item2 = wpArrayPop(i32, array2);
|
||||
|
||||
result = item1 == 8 && item2 == 0;
|
||||
|
||||
@@ -262,12 +262,12 @@ WpTestFuncResult test_i32_array_pop(void) {
|
||||
WpTestFuncResult test_i32_array_clear(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wapp_array_count(array) == 9;
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wpArrayCount(array) == 9;
|
||||
|
||||
wapp_array_clear(i32, array);
|
||||
wpArrayClear(i32, array);
|
||||
|
||||
result = result && wapp_array_count(array) == 0;
|
||||
result = result && wpArrayCount(array) == 0;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
WpTestFuncResult test_i32_array(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wapp_array_count(array) == 7 && wapp_array_capacity(array) == 16;
|
||||
WpI32Array array = wpArray(i32, 1, 2, 3, 4, 5, 6, 7);
|
||||
result = wpArrayCount(array) == 7 && wpArrayCapacity(array) == 16;
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)(index + 1));
|
||||
|
||||
++index;
|
||||
@@ -25,11 +25,11 @@ WpTestFuncResult test_i32_array(void) {
|
||||
WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array1) == 0 && wapp_array_capacity(array1) == 64;
|
||||
WpI32Array array1 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array1) == 0 && wpArrayCapacity(array1) == 64;
|
||||
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 64, ARRAY_INIT_FILLED);
|
||||
result = wapp_array_count(array2) == 64 && wapp_array_capacity(array2) == 64;
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_FILLED);
|
||||
result = wpArrayCount(array2) == 64 && wpArrayCapacity(array2) == 64;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -37,14 +37,14 @@ WpTestFuncResult test_i32_array_with_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_get(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(i32, array, index);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)index);
|
||||
|
||||
++index;
|
||||
@@ -57,16 +57,16 @@ WpTestFuncResult test_i32_array_get(void) {
|
||||
WpTestFuncResult test_i32_array_set(void) {
|
||||
b8 result = true;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
i32 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
i32 num = (i32)(index * 2);
|
||||
wapp_array_set(i32, array, index, &num);
|
||||
item = wapp_array_get(i32, array, index);
|
||||
wpArraySet(i32, array, index, &num);
|
||||
item = wpArrayGet(i32, array, index);
|
||||
result = result && item && (*item == (i32)(index * 2));
|
||||
|
||||
++index;
|
||||
@@ -79,19 +79,19 @@ WpTestFuncResult test_i32_array_set(void) {
|
||||
WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array_with_capacity(i32, 64, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayWithCapacity(i32, 64, WP_ARRAY_INIT_NONE);
|
||||
i32 item1 = 10;
|
||||
wapp_array_append_capped(i32, array, &item1);
|
||||
wpArrayAppendCapped(i32, array, &item1);
|
||||
|
||||
result = wapp_array_count(array) == 1;
|
||||
i32 *item = wapp_array_get(i32, array, 0);
|
||||
result = wpArrayCount(array) == 1;
|
||||
i32 *item = wpArrayGet(i32, array, 0);
|
||||
result = result && item && *item == 10;
|
||||
|
||||
array = wapp_array(i32, 1);
|
||||
array = wpArray(i32, 1);
|
||||
i32 item2 = 10;
|
||||
wapp_array_append_capped(i32, array, &item2);
|
||||
wpArrayAppendCapped(i32, array, &item2);
|
||||
|
||||
result = result && wapp_array_count(array) == 2;
|
||||
result = result && wpArrayCount(array) == 2;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -99,14 +99,14 @@ WpTestFuncResult test_i32_array_append_capped(void) {
|
||||
WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4);
|
||||
I32Array array2 = wapp_array(i32, 10, 20);
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4);
|
||||
WpI32Array array2 = wpArray(i32, 10, 20);
|
||||
|
||||
result = wapp_array_count(array1) == 4 && wapp_array_count(array2) == 2;
|
||||
result = wpArrayCount(array1) == 4 && wpArrayCount(array2) == 2;
|
||||
|
||||
wapp_array_extend_capped(i32, array1, array2);
|
||||
wpArrayExtendCapped(i32, array1, array2);
|
||||
|
||||
result = result && wapp_array_count(array1) == 6;
|
||||
result = result && wpArrayCount(array1) == 6;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -114,31 +114,31 @@ WpTestFuncResult test_i32_array_extend_capped(void) {
|
||||
WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
|
||||
u64 expected_count = 5;
|
||||
wapp_array_copy_capped(i32, dst1, src);
|
||||
result = wapp_array_count(dst1) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst1, src);
|
||||
result = wpArrayCount(dst1) == expected_count;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst1, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst1, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 4;
|
||||
wapp_array_copy_capped(i32, dst2, src);
|
||||
result = result && wapp_array_count(dst2) == expected_count;
|
||||
wpArrayCopyCapped(i32, dst2, src);
|
||||
result = result && wpArrayCount(dst2) == expected_count;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, dst2, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, dst2, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
@@ -150,13 +150,13 @@ WpTestFuncResult test_i32_array_copy_capped(void) {
|
||||
WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
u64 capacity = 32;
|
||||
I32Array array = wapp_array_alloc_capacity(i32, &allocator, capacity, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayAllocCapacity(i32, &allocator, capacity, WP_ARRAY_INIT_NONE);
|
||||
|
||||
result = array && wapp_array_capacity(array) == capacity;
|
||||
result = array && wpArrayCapacity(array) == capacity;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -164,12 +164,12 @@ WpTestFuncResult test_i32_array_alloc_capacity(void) {
|
||||
WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
|
||||
i32 num = 10;
|
||||
I32Array arr_ptr = wapp_array_append_alloc(i32, &allocator, array1, &num, ARRAY_INIT_NONE);
|
||||
WpI32Array arr_ptr = wpArrayAppendAlloc(i32, &allocator, array1, &num, WP_ARRAY_INIT_NONE);
|
||||
result = arr_ptr == array1;
|
||||
|
||||
u64 count = 4;
|
||||
@@ -177,14 +177,14 @@ WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
num = (i32)index;
|
||||
arr_ptr = wapp_array_append_alloc(i32, &allocator, array2, &num, ARRAY_INIT_NONE);
|
||||
arr_ptr = wpArrayAppendAlloc(i32, &allocator, array2, &num, WP_ARRAY_INIT_NONE);
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
}
|
||||
result = result && arr_ptr != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -192,18 +192,18 @@ WpTestFuncResult test_i32_array_append_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array array1 = wapp_array(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array(i32, 1, 2);
|
||||
I32Array array3 = wapp_array(i32, 1, 2, 3, 4);
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array array1 = wpArray(i32, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array3 = wpArray(i32, 1, 2, 3, 4);
|
||||
|
||||
I32Array array = wapp_array_extend_alloc(i32, &allocator, array1, array3, ARRAY_INIT_NONE);
|
||||
WpI32Array array = wpArrayExtendAlloc(i32, &allocator, array1, array3, WP_ARRAY_INIT_NONE);
|
||||
result = array == array1;
|
||||
|
||||
array = wapp_array_extend_alloc(i32, &allocator, array2, array3, ARRAY_INIT_NONE);
|
||||
array = wpArrayExtendAlloc(i32, &allocator, array2, array3, WP_ARRAY_INIT_NONE);
|
||||
result = result && array != array2;
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -211,39 +211,39 @@ WpTestFuncResult test_i32_array_extend_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
b8 result;
|
||||
|
||||
WpAllocator allocator = wapp_mem_arena_allocator_init(MiB(4));
|
||||
I32Array src = wapp_array(i32, 1, 2, 3, 4, 5);
|
||||
I32Array dst1 = wapp_array(i32, 1, 2, 3, 4, 5, 6);
|
||||
I32Array dst2 = wapp_array(i32, 1, 2);
|
||||
I32Array array = nullptr;
|
||||
WpAllocator allocator = wpMemArenaAllocatorInit(MiB(4));
|
||||
WpI32Array src = wpArray(i32, 1, 2, 3, 4, 5);
|
||||
WpI32Array dst1 = wpArray(i32, 1, 2, 3, 4, 5, 6);
|
||||
WpI32Array dst2 = wpArray(i32, 1, 2);
|
||||
WpI32Array array = nullptr;
|
||||
|
||||
u64 expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst1, src, ARRAY_INIT_NONE);
|
||||
result = wapp_array_count(array) == expected_count && array == dst1;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst1, src, WP_ARRAY_INIT_NONE);
|
||||
result = wpArrayCount(array) == expected_count && array == dst1;
|
||||
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
expected_count = 5;
|
||||
array = wapp_array_copy_alloc(i32, &allocator, dst2, src, ARRAY_INIT_NONE);
|
||||
result = result && wapp_array_count(array) == expected_count && array != dst2;
|
||||
array = wpArrayCopyAlloc(i32, &allocator, dst2, src, WP_ARRAY_INIT_NONE);
|
||||
result = result && wpArrayCount(array) == expected_count && array != dst2;
|
||||
|
||||
index = 0;
|
||||
running = true;
|
||||
while (running) {
|
||||
result = result && (*wapp_array_get(i32, src, index) == *wapp_array_get(i32, array, index));
|
||||
result = result && (*wpArrayGet(i32, src, index) == *wpArrayGet(i32, array, index));
|
||||
|
||||
++index;
|
||||
running = index < expected_count;
|
||||
}
|
||||
|
||||
wapp_mem_arena_allocator_destroy(&allocator);
|
||||
wpMemArenaAllocatorDestroy(&allocator);
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -251,12 +251,12 @@ WpTestFuncResult test_i32_array_copy_alloc(void) {
|
||||
WpTestFuncResult test_i32_array_clear(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wapp_array_count(array) == 9;
|
||||
WpI32Array array = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
result = wpArrayCount(array) == 9;
|
||||
|
||||
wapp_array_clear(i32, array);
|
||||
wpArrayClear(i32, array);
|
||||
|
||||
result = result && wapp_array_count(array) == 0;
|
||||
result = result && wpArrayCount(array) == 0;
|
||||
|
||||
return wpTesterResult(result);
|
||||
}
|
||||
@@ -264,11 +264,11 @@ WpTestFuncResult test_i32_array_clear(void) {
|
||||
WpTestFuncResult test_i32_array_pop(void) {
|
||||
b8 result;
|
||||
|
||||
I32Array array1 = wapp_array(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
I32Array array2 = wapp_array_with_capacity(i32, 32, ARRAY_INIT_NONE);
|
||||
WpI32Array array1 = wpArray(i32, 0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
WpI32Array array2 = wpArrayWithCapacity(i32, 32, WP_ARRAY_INIT_NONE);
|
||||
|
||||
i32 item1 = wapp_array_pop(i32, array1);
|
||||
i32 item2 = wapp_array_pop(i32, array2);
|
||||
i32 item1 = wpArrayPop(i32, array1);
|
||||
i32 item2 = wpArrayPop(i32, array2);
|
||||
|
||||
result = item1 == 8 && item2 == 0;
|
||||
|
||||
|
||||
@@ -6,15 +6,15 @@ WpTestFuncResult test_str8_array(void) {
|
||||
b8 result;
|
||||
|
||||
WpStr8 expected[] = {wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye")};
|
||||
WpStr8Array array = wapp_array(WpStr8, wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye"));
|
||||
result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8;
|
||||
WpStr8Array array = wpArray(WpStr8, wpStr8Lit("Hello"), wpStr8Lit("Hi"), wpStr8Lit("Bye"));
|
||||
result = wpArrayCount(array) == 3 && wpArrayCapacity(array) == 8;
|
||||
|
||||
WpStr8 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(WpStr8, array, index);
|
||||
item = wpArrayGet(WpStr8, array, index);
|
||||
result = result && item && (wpStr8Equal(item, &expected[index]));
|
||||
|
||||
++index;
|
||||
|
||||
@@ -10,16 +10,16 @@ WpTestFuncResult test_str8_array(void) {
|
||||
WpStr8 str1 = wpStr8Lit("Hello");
|
||||
WpStr8 str2 = wpStr8Lit("Hi");
|
||||
WpStr8 str3 = wpStr8Lit("Bye");
|
||||
WpStr8Array array = wapp_array(WpStr8, str1, str2, str3);
|
||||
WpStr8Array array = wpArray(WpStr8, str1, str2, str3);
|
||||
|
||||
result = wapp_array_count(array) == 3 && wapp_array_capacity(array) == 8;
|
||||
result = wpArrayCount(array) == 3 && wpArrayCapacity(array) == 8;
|
||||
|
||||
WpStr8 *item;
|
||||
u64 count = wapp_array_count(array);
|
||||
u64 count = wpArrayCount(array);
|
||||
u64 index = 0;
|
||||
b8 running = true;
|
||||
while (running) {
|
||||
item = wapp_array_get(WpStr8, array, index);
|
||||
item = wpArrayGet(WpStr8, array, index);
|
||||
result = result && item && (wpStr8Equal(item, &expected[index]));
|
||||
|
||||
++index;
|
||||
|
||||
Reference in New Issue
Block a user