From 12f083edb0f4bfc0588d36087a7db1bcbbf92779 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 4 May 2025 23:26:03 +0100 Subject: [PATCH] Add code generation for array --- codegen/__main__.py | 7 + codegen/array/make_array.py | 355 ++ codegen/array/snippets/alloc_capacity | 18 + codegen/array/snippets/append_alloc | 20 + codegen/array/snippets/append_capped | 5 + codegen/array/snippets/array_get | 5 + codegen/array/snippets/array_pop | 5 + codegen/array/snippets/array_set | 5 + codegen/array/snippets/clear | 5 + codegen/array/snippets/copy_alloc | 20 + codegen/array/snippets/copy_capped | 16 + codegen/array/snippets/extend_alloc | 21 + codegen/array/snippets/extend_capped | 19 + codegen/array/snippets/stack_array | 5 + codegen/array/snippets/stack_capacity_array | 1 + codegen/dbl_list/make_dbl_list.py | 2 +- src/primitives/array/array.c | 3453 +++++++++++++++++++ src/primitives/array/array.h | 505 +++ 18 files changed, 4466 insertions(+), 1 deletion(-) create mode 100644 codegen/array/make_array.py create mode 100644 codegen/array/snippets/alloc_capacity create mode 100644 codegen/array/snippets/append_alloc create mode 100644 codegen/array/snippets/append_capped create mode 100644 codegen/array/snippets/array_get create mode 100644 codegen/array/snippets/array_pop create mode 100644 codegen/array/snippets/array_set create mode 100644 codegen/array/snippets/clear create mode 100644 codegen/array/snippets/copy_alloc create mode 100644 codegen/array/snippets/copy_capped create mode 100644 codegen/array/snippets/extend_alloc create mode 100644 codegen/array/snippets/extend_capped create mode 100644 codegen/array/snippets/stack_array create mode 100644 codegen/array/snippets/stack_capacity_array create mode 100644 src/primitives/array/array.c create mode 100644 src/primitives/array/array.h diff --git a/codegen/__main__.py b/codegen/__main__.py index 239bc2f..e9fb70b 100644 --- a/codegen/__main__.py +++ b/codegen/__main__.py @@ -1,10 +1,12 @@ from typing import Dict from codegen.datatypes import CDataType from codegen.dbl_list.make_dbl_list import DblListData, make_dbl_list +from codegen.array.make_array import ArrayData, make_array def main(): gen_dbl_list() + gen_array() def gen_dbl_list(): @@ -12,5 +14,10 @@ def gen_dbl_list(): make_dbl_list(datatypes) +def gen_array(): + datatypes: Dict[CDataType, ArrayData] = {} + make_array(datatypes) + + if __name__ == "__main__": main() diff --git a/codegen/array/make_array.py b/codegen/array/make_array.py new file mode 100644 index 0000000..7fd249d --- /dev/null +++ b/codegen/array/make_array.py @@ -0,0 +1,355 @@ +from pathlib import Path +from dataclasses import dataclass, field +from typing import List, Dict +from codegen.constants import WAPP_SRC_ROOT +from codegen.utils import load_func_body_from_file, convert_to_relative +from codegen.datatypes import ( + CDataType, + CMacro, + CStruct, + CFunc, + CHeader, + CSource, + CArg, + CType, + CPointer, + CPointerType, + CQualifier, + CInclude, + get_datatype_string, +) + + +@dataclass +class ArrayData: + array_typename: str + hdr_decl_types: List[CStruct] = field(default_factory=list) + src_decl_types: List[CStruct] = field(default_factory=list) + + +def make_array(user_datatypes: Dict[CDataType, ArrayData] = {}): + def __format_func_body( + filename: Path, + type_string: str, + type_string_upper: str, + type_string_lower: str, + array_typename: str + ): + return load_func_body_from_file(filename).format( + T=type_string, + ArrayType=array_typename, + Tupper=type_string_upper, + Tlower=type_string_lower, + ) + + out_dir = WAPP_SRC_ROOT / "primitives" / "array" + out_dir.mkdir(parents=True, exist_ok=True) + + common_includes: List[CInclude] = [ + CInclude(header="stdbool.h"), + CInclude( + header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "mem_allocator" / "mem_allocator.h", out_dir)).replace("\\", "/"), + local=True, + ), + CInclude( + header=str(convert_to_relative(WAPP_SRC_ROOT / "primitives" / "strings" / "str8" / "str8.h", out_dir)).replace("\\", "/"), + local=True, + ), + CInclude( + header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "misc" / "misc_utils.h", out_dir)).replace("\\", "/"), + local=True, + ), + ] + + common_decl_types: List[CStruct] = [] + + datatypes: dict[CDataType, ArrayData] = { + "Str8": ArrayData( + array_typename="Str8Array", + ), + } + + for _type in CType: + if _type == CType.VOID: + datatypes["void *"] = ArrayData( + array_typename="VoidPArray", + ) + continue + elif _type == CType.BOOL: + datatypes[_type.value] = ArrayData( + array_typename="BoolArray", + ) + continue + + type_title = _type.value.title() + datatypes[_type.value] = ArrayData( + array_typename=f"{type_title}Array", + ) + + datatypes.update(user_datatypes) + + snippets_dir = Path(__file__).parent / "snippets" + + header = CHeader( + name="array", + decl_types=[*common_decl_types], + includes=[], + types=[], + funcs=[] + ) + + source = CSource( + name=header.name, + decl_types=[*common_decl_types], + includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")], + internal_funcs=[], + funcs=header.funcs + ) + + if len(common_includes) > 0: + header.includes.extend(common_includes) + source.includes.extend(common_includes) + + + for _type, array_data in datatypes.items(): + type_string = get_datatype_string(_type) + clean_type_string = type_string.replace(" ", "").replace("*", "_ptr") + type_string_upper = clean_type_string.upper() + type_string_lower = clean_type_string.lower() + + array = CStruct( + name=array_data.array_typename, + cargs=[ + CArg(name="items", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)), + CArg(name="count", _type=CType.U64), + CArg(name="capacity", _type=CType.U64), + ], + ) + + stack_array_macro = CMacro( + name=f"wapp_{type_string_lower}_array(...)", + value=__format_func_body( + filename=snippets_dir / "stack_array", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + stack_capacity_array_macro = CMacro( + name=f"wapp_{type_string_lower}_array_with_capacity(CAPACITY)", + value=__format_func_body( + filename=snippets_dir / "stack_capacity_array", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + get_func = CFunc( + name=f"wapp_{type_string_lower}_array_get", + ret_type=type_string, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="index", _type=CType.U64), + ], + body=__format_func_body( + filename=snippets_dir / "array_get", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + pointer=CPointer(CPointerType.SINGLE), + ) + + set_func = CFunc( + name=f"wapp_{type_string_lower}_array_set", + ret_type=CType.VOID, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + CArg(name="index", _type=CType.U64), + CArg(name="item", _type=type_string), + ], + body=__format_func_body( + filename=snippets_dir / "array_set", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + append_capped_func = CFunc( + name=f"wapp_{type_string_lower}_array_append_capped", + ret_type=CType.VOID, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + CArg(name="item", _type=type_string), + ], + body=__format_func_body( + filename=snippets_dir / "append_capped", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + extend_capped_func = CFunc( + name=f"wapp_{type_string_lower}_array_extend_capped", + ret_type=CType.VOID, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + CArg(name="other", _type=array, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + ], + body=__format_func_body( + filename=snippets_dir / "extend_capped", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + clear_func = CFunc( + name=f"wapp_{type_string_lower}_array_clear", + ret_type=CType.VOID, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + ], + body=__format_func_body( + filename=snippets_dir / "clear", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + pop_func = CFunc( + name=f"wapp_{type_string_lower}_array_pop", + ret_type=type_string, + args=[ + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + ], + body=__format_func_body( + filename=snippets_dir / "array_pop", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + copy_capped_func = CFunc( + name=f"wapp_{type_string_lower}_array_copy_capped", + ret_type=CType.VOID, + args=[ + CArg(name="src", _type=array, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="dst", _type=array, pointer=CPointer(CPointerType.SINGLE)), + ], + body=__format_func_body( + filename=snippets_dir / "copy_capped", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + ) + + alloc_capacity_func = CFunc( + name=f"wapp_{type_string_lower}_array_alloc_capacity", + ret_type=array, + args=[ + CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="capacity", _type=CType.U64), + ], + body=__format_func_body( + filename=snippets_dir / "alloc_capacity", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + pointer=CPointer(CPointerType.SINGLE), + ) + + append_alloc_func = CFunc( + name=f"wapp_{type_string_lower}_array_append_alloc", + ret_type=array, + args=[ + CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + CArg(name="item", _type=type_string), + ], + body=__format_func_body( + filename=snippets_dir / "append_alloc", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + pointer=CPointer(CPointerType.SINGLE), + ) + + extend_alloc_func = CFunc( + name=f"wapp_{type_string_lower}_array_extend_alloc", + ret_type=array, + args=[ + CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="array", _type=array, pointer=CPointer(CPointerType.SINGLE)), + CArg(name="other", _type=array, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + ], + body=__format_func_body( + filename=snippets_dir / "extend_alloc", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + pointer=CPointer(CPointerType.SINGLE), + ) + + copy_alloc_func = CFunc( + name=f"wapp_{type_string_lower}_array_copy_alloc", + ret_type=array, + args=[ + CArg(name="allocator", _type="Allocator", pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="src", _type=array, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), + CArg(name="dst", _type=array, pointer=CPointer(CPointerType.SINGLE)), + ], + body=__format_func_body( + filename=snippets_dir / "copy_alloc", + type_string=type_string, + type_string_upper=type_string_upper, + type_string_lower=type_string_lower, + array_typename=array_data.array_typename, + ), + pointer=CPointer(CPointerType.SINGLE), + ) + + header.decl_types.extend(array_data.hdr_decl_types) + header.macros.extend([stack_array_macro, stack_capacity_array_macro]) + header.types.extend([array]) + header.funcs.extend([ + get_func, + set_func, + append_capped_func, + extend_capped_func, + clear_func, + pop_func, + copy_capped_func, + alloc_capacity_func, + append_alloc_func, + extend_alloc_func, + copy_alloc_func, + ]) + + source.decl_types.extend(array_data.src_decl_types) + source.funcs = header.funcs + + header.save(out_dir) + source.save(out_dir) diff --git a/codegen/array/snippets/alloc_capacity b/codegen/array/snippets/alloc_capacity new file mode 100644 index 0000000..0b030cb --- /dev/null +++ b/codegen/array/snippets/alloc_capacity @@ -0,0 +1,18 @@ + u64 allocation_size = sizeof({ArrayType}) + sizeof({T}) * capacity; + {ArrayType} *array = NULL; + + if (!allocator) {{ + goto RETURN_{Tupper}_ARRAY_ALLOC; + }} + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) {{ + goto RETURN_{Tupper}_ARRAY_ALLOC; + }} + + array->items = ({T} *)((u8 *)array + sizeof({ArrayType})); + array->count = 0; + array->capacity = capacity; + +RETURN_{Tupper}_ARRAY_ALLOC: + return array; diff --git a/codegen/array/snippets/append_alloc b/codegen/array/snippets/append_alloc new file mode 100644 index 0000000..7ffd5e1 --- /dev/null +++ b/codegen/array/snippets/append_alloc @@ -0,0 +1,20 @@ + {ArrayType} *output = array; + + if (!allocator || !array) {{ + goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC; + }} + + if (array->count >= array->capacity) {{ + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity); + if (!output) {{ + output = array; + goto RETURN_{Tupper}_ARRAY_APPEND_ALLOC; + }} + wapp_{Tlower}_array_copy_capped(array, output); + }} + + wapp_{Tlower}_array_append_capped(output, item); + +RETURN_{Tupper}_ARRAY_APPEND_ALLOC: + return output; diff --git a/codegen/array/snippets/append_capped b/codegen/array/snippets/append_capped new file mode 100644 index 0000000..fb0e63b --- /dev/null +++ b/codegen/array/snippets/append_capped @@ -0,0 +1,5 @@ + if (!array || array->count >= array->capacity) {{ + return; + }} + + array->items[(array->count)++] = item; diff --git a/codegen/array/snippets/array_get b/codegen/array/snippets/array_get new file mode 100644 index 0000000..615d681 --- /dev/null +++ b/codegen/array/snippets/array_get @@ -0,0 +1,5 @@ + if (!array || index >= array->count) {{ + return NULL; + }} + + return &(array->items[index]); diff --git a/codegen/array/snippets/array_pop b/codegen/array/snippets/array_pop new file mode 100644 index 0000000..5ee63cc --- /dev/null +++ b/codegen/array/snippets/array_pop @@ -0,0 +1,5 @@ + if (!array || array->count == 0) {{ + return ({T}){{0}}; + }} + + return array->items[--(array->count)]; diff --git a/codegen/array/snippets/array_set b/codegen/array/snippets/array_set new file mode 100644 index 0000000..fd41402 --- /dev/null +++ b/codegen/array/snippets/array_set @@ -0,0 +1,5 @@ + if (!array || index >= array->count) {{ + return; + }} + + array->items[index] = item; diff --git a/codegen/array/snippets/clear b/codegen/array/snippets/clear new file mode 100644 index 0000000..5ae2d50 --- /dev/null +++ b/codegen/array/snippets/clear @@ -0,0 +1,5 @@ + if (!array) {{ + return; + }} + + array->count = 0; diff --git a/codegen/array/snippets/copy_alloc b/codegen/array/snippets/copy_alloc new file mode 100644 index 0000000..eff1280 --- /dev/null +++ b/codegen/array/snippets/copy_alloc @@ -0,0 +1,20 @@ + {ArrayType} *output = dst; + + if (!allocator || !src || !dst) {{ + goto RETURN_{Tupper}_ARRAY_COPY_ALLOC; + }} + + if (src->count >= dst->capacity) {{ + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity); + if (!output) {{ + output = dst; + goto RETURN_{Tupper}_ARRAY_COPY_ALLOC; + }} + }} + + wapp_{Tlower}_array_clear(output); + wapp_{Tlower}_array_copy_capped(src, output); + +RETURN_{Tupper}_ARRAY_COPY_ALLOC: + return output; diff --git a/codegen/array/snippets/copy_capped b/codegen/array/snippets/copy_capped new file mode 100644 index 0000000..28c348e --- /dev/null +++ b/codegen/array/snippets/copy_capped @@ -0,0 +1,16 @@ + if (!src || !dst) {{ + return; + }} + + wapp_{Tlower}_array_clear(dst); + + {T} *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) {{ + item = wapp_{Tlower}_array_get(src, i); + if (!item) {{ + continue; + }} + + wapp_{Tlower}_array_append_capped(dst, *item); + }} diff --git a/codegen/array/snippets/extend_alloc b/codegen/array/snippets/extend_alloc new file mode 100644 index 0000000..971fd33 --- /dev/null +++ b/codegen/array/snippets/extend_alloc @@ -0,0 +1,21 @@ + {ArrayType} *output = array; + + if (!allocator || !array || !other) {{ + goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC; + }} + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) {{ + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_{Tlower}_array_alloc_capacity(allocator, new_capacity); + if (!output) {{ + output = array; + goto RETURN_{Tupper}_ARRAY_EXTEND_ALLOC; + }} + wapp_{Tlower}_array_copy_capped(array, output); + }} + + wapp_{Tlower}_array_extend_capped(output, other); + +RETURN_{Tupper}_ARRAY_EXTEND_ALLOC: + return output; diff --git a/codegen/array/snippets/extend_capped b/codegen/array/snippets/extend_capped new file mode 100644 index 0000000..8205b88 --- /dev/null +++ b/codegen/array/snippets/extend_capped @@ -0,0 +1,19 @@ + if (!array || !other) {{ + return; + }} + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) {{ + return; + }} + + {T} *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) {{ + item = wapp_{Tlower}_array_get(other, i); + if (!item) {{ + continue; + }} + + wapp_{Tlower}_array_append_capped(array, *item); + }} diff --git a/codegen/array/snippets/stack_array b/codegen/array/snippets/stack_array new file mode 100644 index 0000000..e513a40 --- /dev/null +++ b/codegen/array/snippets/stack_array @@ -0,0 +1,5 @@ +(({ArrayType}){{ \ + .items = ({T}[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count({T}, __VA_ARGS__) * 2)]){{__VA_ARGS__}}, \ + .count = wapp_misc_utils_va_args_count({T}, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count({T}, __VA_ARGS__) * 2) \ +}}) diff --git a/codegen/array/snippets/stack_capacity_array b/codegen/array/snippets/stack_capacity_array new file mode 100644 index 0000000..0b03163 --- /dev/null +++ b/codegen/array/snippets/stack_capacity_array @@ -0,0 +1 @@ +(({ArrayType}){{.items = ({T}[CAPACITY]){{0}}, .count = 0, .capacity = CAPACITY}}) diff --git a/codegen/dbl_list/make_dbl_list.py b/codegen/dbl_list/make_dbl_list.py index 05d54bd..42499b8 100644 --- a/codegen/dbl_list/make_dbl_list.py +++ b/codegen/dbl_list/make_dbl_list.py @@ -45,7 +45,7 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}): Tlower=type_string_lower, ) - out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list" + out_dir = WAPP_SRC_ROOT / "primitives" / "dbl_list" out_dir.mkdir(parents=True, exist_ok=True) common_includes: List[CInclude] = [ diff --git a/src/primitives/array/array.c b/src/primitives/array/array.c new file mode 100644 index 0000000..903a160 --- /dev/null +++ b/src/primitives/array/array.c @@ -0,0 +1,3453 @@ +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#include "./array.h" +#include "../mem_allocator/mem_allocator.h" +#include "../strings/str8/str8.h" +#include "../../common/misc/misc_utils.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include +#include + +Str8 *wapp_str8_array_get(const Str8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_str8_array_append_capped(Str8Array *array, Str8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + Str8 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_str8_array_get(other, i); + if (!item) { + continue; + } + + wapp_str8_array_append_capped(array, *item); + } +} + +void wapp_str8_array_clear(Str8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +Str8 wapp_str8_array_pop(Str8Array *array) { + if (!array || array->count == 0) { + return (Str8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_str8_array_clear(dst); + + Str8 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_str8_array_get(src, i); + if (!item) { + continue; + } + + wapp_str8_array_append_capped(dst, *item); + } +} + +Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(Str8Array) + sizeof(Str8) * capacity; + Str8Array *array = NULL; + + if (!allocator) { + goto RETURN_STR8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_STR8_ARRAY_ALLOC; + } + + array->items = (Str8 *)((u8 *)array + sizeof(Str8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_STR8_ARRAY_ALLOC: + return array; +} + +Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item) { + Str8Array *output = array; + + if (!allocator || !array) { + goto RETURN_STR8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_STR8_ARRAY_APPEND_ALLOC; + } + wapp_str8_array_copy_capped(array, output); + } + + wapp_str8_array_append_capped(output, item); + +RETURN_STR8_ARRAY_APPEND_ALLOC: + return output; +} + +Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other) { + Str8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_STR8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_STR8_ARRAY_EXTEND_ALLOC; + } + wapp_str8_array_copy_capped(array, output); + } + + wapp_str8_array_extend_capped(output, other); + +RETURN_STR8_ARRAY_EXTEND_ALLOC: + return output; +} + +Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst) { + Str8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_STR8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_str8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_STR8_ARRAY_COPY_ALLOC; + } + } + + wapp_str8_array_clear(output); + wapp_str8_array_copy_capped(src, output); + +RETURN_STR8_ARRAY_COPY_ALLOC: + return output; +} + +void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + void * *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_void_ptr_array_get(other, i); + if (!item) { + continue; + } + + wapp_void_ptr_array_append_capped(array, *item); + } +} + +void wapp_void_ptr_array_clear(VoidPArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +void * wapp_void_ptr_array_pop(VoidPArray *array) { + if (!array || array->count == 0) { + return (void *){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst) { + if (!src || !dst) { + return; + } + + wapp_void_ptr_array_clear(dst); + + void * *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_void_ptr_array_get(src, i); + if (!item) { + continue; + } + + wapp_void_ptr_array_append_capped(dst, *item); + } +} + +VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(VoidPArray) + sizeof(void *) * capacity; + VoidPArray *array = NULL; + + if (!allocator) { + goto RETURN_VOID_PTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_VOID_PTR_ARRAY_ALLOC; + } + + array->items = (void * *)((u8 *)array + sizeof(VoidPArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_VOID_PTR_ARRAY_ALLOC: + return array; +} + +VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item) { + VoidPArray *output = array; + + if (!allocator || !array) { + goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_VOID_PTR_ARRAY_APPEND_ALLOC; + } + wapp_void_ptr_array_copy_capped(array, output); + } + + wapp_void_ptr_array_append_capped(output, item); + +RETURN_VOID_PTR_ARRAY_APPEND_ALLOC: + return output; +} + +VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other) { + VoidPArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC; + } + wapp_void_ptr_array_copy_capped(array, output); + } + + wapp_void_ptr_array_extend_capped(output, other); + +RETURN_VOID_PTR_ARRAY_EXTEND_ALLOC: + return output; +} + +VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst) { + VoidPArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_void_ptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_VOID_PTR_ARRAY_COPY_ALLOC; + } + } + + wapp_void_ptr_array_clear(output); + wapp_void_ptr_array_copy_capped(src, output); + +RETURN_VOID_PTR_ARRAY_COPY_ALLOC: + return output; +} + +bool *wapp_bool_array_get(const BoolArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_bool_array_set(BoolArray *array, u64 index, bool item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_bool_array_append_capped(BoolArray *array, bool item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + bool *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_bool_array_get(other, i); + if (!item) { + continue; + } + + wapp_bool_array_append_capped(array, *item); + } +} + +void wapp_bool_array_clear(BoolArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +bool wapp_bool_array_pop(BoolArray *array) { + if (!array || array->count == 0) { + return (bool){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst) { + if (!src || !dst) { + return; + } + + wapp_bool_array_clear(dst); + + bool *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_bool_array_get(src, i); + if (!item) { + continue; + } + + wapp_bool_array_append_capped(dst, *item); + } +} + +BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(BoolArray) + sizeof(bool) * capacity; + BoolArray *array = NULL; + + if (!allocator) { + goto RETURN_BOOL_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_BOOL_ARRAY_ALLOC; + } + + array->items = (bool *)((u8 *)array + sizeof(BoolArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_BOOL_ARRAY_ALLOC: + return array; +} + +BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item) { + BoolArray *output = array; + + if (!allocator || !array) { + goto RETURN_BOOL_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_BOOL_ARRAY_APPEND_ALLOC; + } + wapp_bool_array_copy_capped(array, output); + } + + wapp_bool_array_append_capped(output, item); + +RETURN_BOOL_ARRAY_APPEND_ALLOC: + return output; +} + +BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other) { + BoolArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_BOOL_ARRAY_EXTEND_ALLOC; + } + wapp_bool_array_copy_capped(array, output); + } + + wapp_bool_array_extend_capped(output, other); + +RETURN_BOOL_ARRAY_EXTEND_ALLOC: + return output; +} + +BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst) { + BoolArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_BOOL_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_bool_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_BOOL_ARRAY_COPY_ALLOC; + } + } + + wapp_bool_array_clear(output); + wapp_bool_array_copy_capped(src, output); + +RETURN_BOOL_ARRAY_COPY_ALLOC: + return output; +} + +char *wapp_char_array_get(const CharArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_char_array_set(CharArray *array, u64 index, char item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_char_array_append_capped(CharArray *array, char item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_char_array_extend_capped(CharArray *array, const CharArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + char *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_char_array_get(other, i); + if (!item) { + continue; + } + + wapp_char_array_append_capped(array, *item); + } +} + +void wapp_char_array_clear(CharArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +char wapp_char_array_pop(CharArray *array) { + if (!array || array->count == 0) { + return (char){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst) { + if (!src || !dst) { + return; + } + + wapp_char_array_clear(dst); + + char *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_char_array_get(src, i); + if (!item) { + continue; + } + + wapp_char_array_append_capped(dst, *item); + } +} + +CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(CharArray) + sizeof(char) * capacity; + CharArray *array = NULL; + + if (!allocator) { + goto RETURN_CHAR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_CHAR_ARRAY_ALLOC; + } + + array->items = (char *)((u8 *)array + sizeof(CharArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_CHAR_ARRAY_ALLOC: + return array; +} + +CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item) { + CharArray *output = array; + + if (!allocator || !array) { + goto RETURN_CHAR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_CHAR_ARRAY_APPEND_ALLOC; + } + wapp_char_array_copy_capped(array, output); + } + + wapp_char_array_append_capped(output, item); + +RETURN_CHAR_ARRAY_APPEND_ALLOC: + return output; +} + +CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other) { + CharArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_CHAR_ARRAY_EXTEND_ALLOC; + } + wapp_char_array_copy_capped(array, output); + } + + wapp_char_array_extend_capped(output, other); + +RETURN_CHAR_ARRAY_EXTEND_ALLOC: + return output; +} + +CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst) { + CharArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_CHAR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_char_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_CHAR_ARRAY_COPY_ALLOC; + } + } + + wapp_char_array_clear(output); + wapp_char_array_copy_capped(src, output); + +RETURN_CHAR_ARRAY_COPY_ALLOC: + return output; +} + +c8 *wapp_c8_array_get(const C8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c8_array_set(C8Array *array, u64 index, c8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c8_array_append_capped(C8Array *array, c8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c8 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_c8_array_get(other, i); + if (!item) { + continue; + } + + wapp_c8_array_append_capped(array, *item); + } +} + +void wapp_c8_array_clear(C8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c8 wapp_c8_array_pop(C8Array *array) { + if (!array || array->count == 0) { + return (c8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c8_array_clear(dst); + + c8 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_c8_array_get(src, i); + if (!item) { + continue; + } + + wapp_c8_array_append_capped(dst, *item); + } +} + +C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C8Array) + sizeof(c8) * capacity; + C8Array *array = NULL; + + if (!allocator) { + goto RETURN_C8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C8_ARRAY_ALLOC; + } + + array->items = (c8 *)((u8 *)array + sizeof(C8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C8_ARRAY_ALLOC: + return array; +} + +C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item) { + C8Array *output = array; + + if (!allocator || !array) { + goto RETURN_C8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C8_ARRAY_APPEND_ALLOC; + } + wapp_c8_array_copy_capped(array, output); + } + + wapp_c8_array_append_capped(output, item); + +RETURN_C8_ARRAY_APPEND_ALLOC: + return output; +} + +C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other) { + C8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C8_ARRAY_EXTEND_ALLOC; + } + wapp_c8_array_copy_capped(array, output); + } + + wapp_c8_array_extend_capped(output, other); + +RETURN_C8_ARRAY_EXTEND_ALLOC: + return output; +} + +C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst) { + C8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C8_ARRAY_COPY_ALLOC; + } + } + + wapp_c8_array_clear(output); + wapp_c8_array_copy_capped(src, output); + +RETURN_C8_ARRAY_COPY_ALLOC: + return output; +} + +c16 *wapp_c16_array_get(const C16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c16_array_set(C16Array *array, u64 index, c16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c16_array_append_capped(C16Array *array, c16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c16 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_c16_array_get(other, i); + if (!item) { + continue; + } + + wapp_c16_array_append_capped(array, *item); + } +} + +void wapp_c16_array_clear(C16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c16 wapp_c16_array_pop(C16Array *array) { + if (!array || array->count == 0) { + return (c16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c16_array_clear(dst); + + c16 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_c16_array_get(src, i); + if (!item) { + continue; + } + + wapp_c16_array_append_capped(dst, *item); + } +} + +C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C16Array) + sizeof(c16) * capacity; + C16Array *array = NULL; + + if (!allocator) { + goto RETURN_C16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C16_ARRAY_ALLOC; + } + + array->items = (c16 *)((u8 *)array + sizeof(C16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C16_ARRAY_ALLOC: + return array; +} + +C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item) { + C16Array *output = array; + + if (!allocator || !array) { + goto RETURN_C16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C16_ARRAY_APPEND_ALLOC; + } + wapp_c16_array_copy_capped(array, output); + } + + wapp_c16_array_append_capped(output, item); + +RETURN_C16_ARRAY_APPEND_ALLOC: + return output; +} + +C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other) { + C16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C16_ARRAY_EXTEND_ALLOC; + } + wapp_c16_array_copy_capped(array, output); + } + + wapp_c16_array_extend_capped(output, other); + +RETURN_C16_ARRAY_EXTEND_ALLOC: + return output; +} + +C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst) { + C16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C16_ARRAY_COPY_ALLOC; + } + } + + wapp_c16_array_clear(output); + wapp_c16_array_copy_capped(src, output); + +RETURN_C16_ARRAY_COPY_ALLOC: + return output; +} + +c32 *wapp_c32_array_get(const C32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_c32_array_set(C32Array *array, u64 index, c32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_c32_array_append_capped(C32Array *array, c32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + c32 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_c32_array_get(other, i); + if (!item) { + continue; + } + + wapp_c32_array_append_capped(array, *item); + } +} + +void wapp_c32_array_clear(C32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +c32 wapp_c32_array_pop(C32Array *array) { + if (!array || array->count == 0) { + return (c32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_c32_array_clear(dst); + + c32 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_c32_array_get(src, i); + if (!item) { + continue; + } + + wapp_c32_array_append_capped(dst, *item); + } +} + +C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(C32Array) + sizeof(c32) * capacity; + C32Array *array = NULL; + + if (!allocator) { + goto RETURN_C32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_C32_ARRAY_ALLOC; + } + + array->items = (c32 *)((u8 *)array + sizeof(C32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_C32_ARRAY_ALLOC: + return array; +} + +C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item) { + C32Array *output = array; + + if (!allocator || !array) { + goto RETURN_C32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C32_ARRAY_APPEND_ALLOC; + } + wapp_c32_array_copy_capped(array, output); + } + + wapp_c32_array_append_capped(output, item); + +RETURN_C32_ARRAY_APPEND_ALLOC: + return output; +} + +C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other) { + C32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_C32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_C32_ARRAY_EXTEND_ALLOC; + } + wapp_c32_array_copy_capped(array, output); + } + + wapp_c32_array_extend_capped(output, other); + +RETURN_C32_ARRAY_EXTEND_ALLOC: + return output; +} + +C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst) { + C32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_C32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_c32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_C32_ARRAY_COPY_ALLOC; + } + } + + wapp_c32_array_clear(output); + wapp_c32_array_copy_capped(src, output); + +RETURN_C32_ARRAY_COPY_ALLOC: + return output; +} + +i8 *wapp_i8_array_get(const I8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i8_array_set(I8Array *array, u64 index, i8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i8_array_append_capped(I8Array *array, i8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i8 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_i8_array_get(other, i); + if (!item) { + continue; + } + + wapp_i8_array_append_capped(array, *item); + } +} + +void wapp_i8_array_clear(I8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i8 wapp_i8_array_pop(I8Array *array) { + if (!array || array->count == 0) { + return (i8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i8_array_clear(dst); + + i8 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_i8_array_get(src, i); + if (!item) { + continue; + } + + wapp_i8_array_append_capped(dst, *item); + } +} + +I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I8Array) + sizeof(i8) * capacity; + I8Array *array = NULL; + + if (!allocator) { + goto RETURN_I8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I8_ARRAY_ALLOC; + } + + array->items = (i8 *)((u8 *)array + sizeof(I8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I8_ARRAY_ALLOC: + return array; +} + +I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item) { + I8Array *output = array; + + if (!allocator || !array) { + goto RETURN_I8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I8_ARRAY_APPEND_ALLOC; + } + wapp_i8_array_copy_capped(array, output); + } + + wapp_i8_array_append_capped(output, item); + +RETURN_I8_ARRAY_APPEND_ALLOC: + return output; +} + +I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other) { + I8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I8_ARRAY_EXTEND_ALLOC; + } + wapp_i8_array_copy_capped(array, output); + } + + wapp_i8_array_extend_capped(output, other); + +RETURN_I8_ARRAY_EXTEND_ALLOC: + return output; +} + +I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst) { + I8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I8_ARRAY_COPY_ALLOC; + } + } + + wapp_i8_array_clear(output); + wapp_i8_array_copy_capped(src, output); + +RETURN_I8_ARRAY_COPY_ALLOC: + return output; +} + +i16 *wapp_i16_array_get(const I16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i16_array_set(I16Array *array, u64 index, i16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i16_array_append_capped(I16Array *array, i16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i16 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_i16_array_get(other, i); + if (!item) { + continue; + } + + wapp_i16_array_append_capped(array, *item); + } +} + +void wapp_i16_array_clear(I16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i16 wapp_i16_array_pop(I16Array *array) { + if (!array || array->count == 0) { + return (i16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i16_array_clear(dst); + + i16 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_i16_array_get(src, i); + if (!item) { + continue; + } + + wapp_i16_array_append_capped(dst, *item); + } +} + +I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I16Array) + sizeof(i16) * capacity; + I16Array *array = NULL; + + if (!allocator) { + goto RETURN_I16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I16_ARRAY_ALLOC; + } + + array->items = (i16 *)((u8 *)array + sizeof(I16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I16_ARRAY_ALLOC: + return array; +} + +I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item) { + I16Array *output = array; + + if (!allocator || !array) { + goto RETURN_I16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I16_ARRAY_APPEND_ALLOC; + } + wapp_i16_array_copy_capped(array, output); + } + + wapp_i16_array_append_capped(output, item); + +RETURN_I16_ARRAY_APPEND_ALLOC: + return output; +} + +I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other) { + I16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I16_ARRAY_EXTEND_ALLOC; + } + wapp_i16_array_copy_capped(array, output); + } + + wapp_i16_array_extend_capped(output, other); + +RETURN_I16_ARRAY_EXTEND_ALLOC: + return output; +} + +I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst) { + I16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I16_ARRAY_COPY_ALLOC; + } + } + + wapp_i16_array_clear(output); + wapp_i16_array_copy_capped(src, output); + +RETURN_I16_ARRAY_COPY_ALLOC: + return output; +} + +i32 *wapp_i32_array_get(const I32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i32_array_set(I32Array *array, u64 index, i32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i32_array_append_capped(I32Array *array, i32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i32 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_i32_array_get(other, i); + if (!item) { + continue; + } + + wapp_i32_array_append_capped(array, *item); + } +} + +void wapp_i32_array_clear(I32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i32 wapp_i32_array_pop(I32Array *array) { + if (!array || array->count == 0) { + return (i32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i32_array_clear(dst); + + i32 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_i32_array_get(src, i); + if (!item) { + continue; + } + + wapp_i32_array_append_capped(dst, *item); + } +} + +I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I32Array) + sizeof(i32) * capacity; + I32Array *array = NULL; + + if (!allocator) { + goto RETURN_I32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I32_ARRAY_ALLOC; + } + + array->items = (i32 *)((u8 *)array + sizeof(I32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I32_ARRAY_ALLOC: + return array; +} + +I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item) { + I32Array *output = array; + + if (!allocator || !array) { + goto RETURN_I32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I32_ARRAY_APPEND_ALLOC; + } + wapp_i32_array_copy_capped(array, output); + } + + wapp_i32_array_append_capped(output, item); + +RETURN_I32_ARRAY_APPEND_ALLOC: + return output; +} + +I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other) { + I32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I32_ARRAY_EXTEND_ALLOC; + } + wapp_i32_array_copy_capped(array, output); + } + + wapp_i32_array_extend_capped(output, other); + +RETURN_I32_ARRAY_EXTEND_ALLOC: + return output; +} + +I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst) { + I32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I32_ARRAY_COPY_ALLOC; + } + } + + wapp_i32_array_clear(output); + wapp_i32_array_copy_capped(src, output); + +RETURN_I32_ARRAY_COPY_ALLOC: + return output; +} + +i64 *wapp_i64_array_get(const I64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_i64_array_set(I64Array *array, u64 index, i64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_i64_array_append_capped(I64Array *array, i64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + i64 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_i64_array_get(other, i); + if (!item) { + continue; + } + + wapp_i64_array_append_capped(array, *item); + } +} + +void wapp_i64_array_clear(I64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +i64 wapp_i64_array_pop(I64Array *array) { + if (!array || array->count == 0) { + return (i64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_i64_array_clear(dst); + + i64 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_i64_array_get(src, i); + if (!item) { + continue; + } + + wapp_i64_array_append_capped(dst, *item); + } +} + +I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(I64Array) + sizeof(i64) * capacity; + I64Array *array = NULL; + + if (!allocator) { + goto RETURN_I64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_I64_ARRAY_ALLOC; + } + + array->items = (i64 *)((u8 *)array + sizeof(I64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_I64_ARRAY_ALLOC: + return array; +} + +I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item) { + I64Array *output = array; + + if (!allocator || !array) { + goto RETURN_I64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I64_ARRAY_APPEND_ALLOC; + } + wapp_i64_array_copy_capped(array, output); + } + + wapp_i64_array_append_capped(output, item); + +RETURN_I64_ARRAY_APPEND_ALLOC: + return output; +} + +I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other) { + I64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_I64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_I64_ARRAY_EXTEND_ALLOC; + } + wapp_i64_array_copy_capped(array, output); + } + + wapp_i64_array_extend_capped(output, other); + +RETURN_I64_ARRAY_EXTEND_ALLOC: + return output; +} + +I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst) { + I64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_I64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_i64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_I64_ARRAY_COPY_ALLOC; + } + } + + wapp_i64_array_clear(output); + wapp_i64_array_copy_capped(src, output); + +RETURN_I64_ARRAY_COPY_ALLOC: + return output; +} + +u8 *wapp_u8_array_get(const U8Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u8_array_set(U8Array *array, u64 index, u8 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u8_array_append_capped(U8Array *array, u8 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u8 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_u8_array_get(other, i); + if (!item) { + continue; + } + + wapp_u8_array_append_capped(array, *item); + } +} + +void wapp_u8_array_clear(U8Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u8 wapp_u8_array_pop(U8Array *array) { + if (!array || array->count == 0) { + return (u8){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u8_array_clear(dst); + + u8 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_u8_array_get(src, i); + if (!item) { + continue; + } + + wapp_u8_array_append_capped(dst, *item); + } +} + +U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U8Array) + sizeof(u8) * capacity; + U8Array *array = NULL; + + if (!allocator) { + goto RETURN_U8_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U8_ARRAY_ALLOC; + } + + array->items = (u8 *)((u8 *)array + sizeof(U8Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U8_ARRAY_ALLOC: + return array; +} + +U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item) { + U8Array *output = array; + + if (!allocator || !array) { + goto RETURN_U8_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U8_ARRAY_APPEND_ALLOC; + } + wapp_u8_array_copy_capped(array, output); + } + + wapp_u8_array_append_capped(output, item); + +RETURN_U8_ARRAY_APPEND_ALLOC: + return output; +} + +U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other) { + U8Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U8_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U8_ARRAY_EXTEND_ALLOC; + } + wapp_u8_array_copy_capped(array, output); + } + + wapp_u8_array_extend_capped(output, other); + +RETURN_U8_ARRAY_EXTEND_ALLOC: + return output; +} + +U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst) { + U8Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U8_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u8_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U8_ARRAY_COPY_ALLOC; + } + } + + wapp_u8_array_clear(output); + wapp_u8_array_copy_capped(src, output); + +RETURN_U8_ARRAY_COPY_ALLOC: + return output; +} + +u16 *wapp_u16_array_get(const U16Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u16_array_set(U16Array *array, u64 index, u16 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u16_array_append_capped(U16Array *array, u16 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u16 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_u16_array_get(other, i); + if (!item) { + continue; + } + + wapp_u16_array_append_capped(array, *item); + } +} + +void wapp_u16_array_clear(U16Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u16 wapp_u16_array_pop(U16Array *array) { + if (!array || array->count == 0) { + return (u16){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u16_array_clear(dst); + + u16 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_u16_array_get(src, i); + if (!item) { + continue; + } + + wapp_u16_array_append_capped(dst, *item); + } +} + +U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U16Array) + sizeof(u16) * capacity; + U16Array *array = NULL; + + if (!allocator) { + goto RETURN_U16_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U16_ARRAY_ALLOC; + } + + array->items = (u16 *)((u8 *)array + sizeof(U16Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U16_ARRAY_ALLOC: + return array; +} + +U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item) { + U16Array *output = array; + + if (!allocator || !array) { + goto RETURN_U16_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U16_ARRAY_APPEND_ALLOC; + } + wapp_u16_array_copy_capped(array, output); + } + + wapp_u16_array_append_capped(output, item); + +RETURN_U16_ARRAY_APPEND_ALLOC: + return output; +} + +U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other) { + U16Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U16_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U16_ARRAY_EXTEND_ALLOC; + } + wapp_u16_array_copy_capped(array, output); + } + + wapp_u16_array_extend_capped(output, other); + +RETURN_U16_ARRAY_EXTEND_ALLOC: + return output; +} + +U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst) { + U16Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U16_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u16_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U16_ARRAY_COPY_ALLOC; + } + } + + wapp_u16_array_clear(output); + wapp_u16_array_copy_capped(src, output); + +RETURN_U16_ARRAY_COPY_ALLOC: + return output; +} + +u32 *wapp_u32_array_get(const U32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u32_array_set(U32Array *array, u64 index, u32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u32_array_append_capped(U32Array *array, u32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u32 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_u32_array_get(other, i); + if (!item) { + continue; + } + + wapp_u32_array_append_capped(array, *item); + } +} + +void wapp_u32_array_clear(U32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u32 wapp_u32_array_pop(U32Array *array) { + if (!array || array->count == 0) { + return (u32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u32_array_clear(dst); + + u32 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_u32_array_get(src, i); + if (!item) { + continue; + } + + wapp_u32_array_append_capped(dst, *item); + } +} + +U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U32Array) + sizeof(u32) * capacity; + U32Array *array = NULL; + + if (!allocator) { + goto RETURN_U32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U32_ARRAY_ALLOC; + } + + array->items = (u32 *)((u8 *)array + sizeof(U32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U32_ARRAY_ALLOC: + return array; +} + +U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item) { + U32Array *output = array; + + if (!allocator || !array) { + goto RETURN_U32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U32_ARRAY_APPEND_ALLOC; + } + wapp_u32_array_copy_capped(array, output); + } + + wapp_u32_array_append_capped(output, item); + +RETURN_U32_ARRAY_APPEND_ALLOC: + return output; +} + +U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other) { + U32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U32_ARRAY_EXTEND_ALLOC; + } + wapp_u32_array_copy_capped(array, output); + } + + wapp_u32_array_extend_capped(output, other); + +RETURN_U32_ARRAY_EXTEND_ALLOC: + return output; +} + +U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst) { + U32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U32_ARRAY_COPY_ALLOC; + } + } + + wapp_u32_array_clear(output); + wapp_u32_array_copy_capped(src, output); + +RETURN_U32_ARRAY_COPY_ALLOC: + return output; +} + +u64 *wapp_u64_array_get(const U64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_u64_array_set(U64Array *array, u64 index, u64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_u64_array_append_capped(U64Array *array, u64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + u64 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_u64_array_get(other, i); + if (!item) { + continue; + } + + wapp_u64_array_append_capped(array, *item); + } +} + +void wapp_u64_array_clear(U64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +u64 wapp_u64_array_pop(U64Array *array) { + if (!array || array->count == 0) { + return (u64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_u64_array_clear(dst); + + u64 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_u64_array_get(src, i); + if (!item) { + continue; + } + + wapp_u64_array_append_capped(dst, *item); + } +} + +U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(U64Array) + sizeof(u64) * capacity; + U64Array *array = NULL; + + if (!allocator) { + goto RETURN_U64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_U64_ARRAY_ALLOC; + } + + array->items = (u64 *)((u8 *)array + sizeof(U64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_U64_ARRAY_ALLOC: + return array; +} + +U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item) { + U64Array *output = array; + + if (!allocator || !array) { + goto RETURN_U64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U64_ARRAY_APPEND_ALLOC; + } + wapp_u64_array_copy_capped(array, output); + } + + wapp_u64_array_append_capped(output, item); + +RETURN_U64_ARRAY_APPEND_ALLOC: + return output; +} + +U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other) { + U64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_U64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_U64_ARRAY_EXTEND_ALLOC; + } + wapp_u64_array_copy_capped(array, output); + } + + wapp_u64_array_extend_capped(output, other); + +RETURN_U64_ARRAY_EXTEND_ALLOC: + return output; +} + +U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst) { + U64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_U64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_u64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_U64_ARRAY_COPY_ALLOC; + } + } + + wapp_u64_array_clear(output); + wapp_u64_array_copy_capped(src, output); + +RETURN_U64_ARRAY_COPY_ALLOC: + return output; +} + +f32 *wapp_f32_array_get(const F32Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f32_array_set(F32Array *array, u64 index, f32 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f32_array_append_capped(F32Array *array, f32 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f32 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_f32_array_get(other, i); + if (!item) { + continue; + } + + wapp_f32_array_append_capped(array, *item); + } +} + +void wapp_f32_array_clear(F32Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f32 wapp_f32_array_pop(F32Array *array) { + if (!array || array->count == 0) { + return (f32){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f32_array_clear(dst); + + f32 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_f32_array_get(src, i); + if (!item) { + continue; + } + + wapp_f32_array_append_capped(dst, *item); + } +} + +F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F32Array) + sizeof(f32) * capacity; + F32Array *array = NULL; + + if (!allocator) { + goto RETURN_F32_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F32_ARRAY_ALLOC; + } + + array->items = (f32 *)((u8 *)array + sizeof(F32Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F32_ARRAY_ALLOC: + return array; +} + +F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item) { + F32Array *output = array; + + if (!allocator || !array) { + goto RETURN_F32_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F32_ARRAY_APPEND_ALLOC; + } + wapp_f32_array_copy_capped(array, output); + } + + wapp_f32_array_append_capped(output, item); + +RETURN_F32_ARRAY_APPEND_ALLOC: + return output; +} + +F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other) { + F32Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F32_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F32_ARRAY_EXTEND_ALLOC; + } + wapp_f32_array_copy_capped(array, output); + } + + wapp_f32_array_extend_capped(output, other); + +RETURN_F32_ARRAY_EXTEND_ALLOC: + return output; +} + +F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst) { + F32Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F32_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f32_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F32_ARRAY_COPY_ALLOC; + } + } + + wapp_f32_array_clear(output); + wapp_f32_array_copy_capped(src, output); + +RETURN_F32_ARRAY_COPY_ALLOC: + return output; +} + +f64 *wapp_f64_array_get(const F64Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f64_array_set(F64Array *array, u64 index, f64 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f64_array_append_capped(F64Array *array, f64 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f64 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_f64_array_get(other, i); + if (!item) { + continue; + } + + wapp_f64_array_append_capped(array, *item); + } +} + +void wapp_f64_array_clear(F64Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f64 wapp_f64_array_pop(F64Array *array) { + if (!array || array->count == 0) { + return (f64){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f64_array_clear(dst); + + f64 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_f64_array_get(src, i); + if (!item) { + continue; + } + + wapp_f64_array_append_capped(dst, *item); + } +} + +F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F64Array) + sizeof(f64) * capacity; + F64Array *array = NULL; + + if (!allocator) { + goto RETURN_F64_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F64_ARRAY_ALLOC; + } + + array->items = (f64 *)((u8 *)array + sizeof(F64Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F64_ARRAY_ALLOC: + return array; +} + +F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item) { + F64Array *output = array; + + if (!allocator || !array) { + goto RETURN_F64_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F64_ARRAY_APPEND_ALLOC; + } + wapp_f64_array_copy_capped(array, output); + } + + wapp_f64_array_append_capped(output, item); + +RETURN_F64_ARRAY_APPEND_ALLOC: + return output; +} + +F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other) { + F64Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F64_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F64_ARRAY_EXTEND_ALLOC; + } + wapp_f64_array_copy_capped(array, output); + } + + wapp_f64_array_extend_capped(output, other); + +RETURN_F64_ARRAY_EXTEND_ALLOC: + return output; +} + +F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst) { + F64Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F64_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f64_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F64_ARRAY_COPY_ALLOC; + } + } + + wapp_f64_array_clear(output); + wapp_f64_array_copy_capped(src, output); + +RETURN_F64_ARRAY_COPY_ALLOC: + return output; +} + +f128 *wapp_f128_array_get(const F128Array *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_f128_array_set(F128Array *array, u64 index, f128 item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_f128_array_append_capped(F128Array *array, f128 item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + f128 *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_f128_array_get(other, i); + if (!item) { + continue; + } + + wapp_f128_array_append_capped(array, *item); + } +} + +void wapp_f128_array_clear(F128Array *array) { + if (!array) { + return; + } + + array->count = 0; +} + +f128 wapp_f128_array_pop(F128Array *array) { + if (!array || array->count == 0) { + return (f128){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst) { + if (!src || !dst) { + return; + } + + wapp_f128_array_clear(dst); + + f128 *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_f128_array_get(src, i); + if (!item) { + continue; + } + + wapp_f128_array_append_capped(dst, *item); + } +} + +F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(F128Array) + sizeof(f128) * capacity; + F128Array *array = NULL; + + if (!allocator) { + goto RETURN_F128_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_F128_ARRAY_ALLOC; + } + + array->items = (f128 *)((u8 *)array + sizeof(F128Array)); + array->count = 0; + array->capacity = capacity; + +RETURN_F128_ARRAY_ALLOC: + return array; +} + +F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item) { + F128Array *output = array; + + if (!allocator || !array) { + goto RETURN_F128_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F128_ARRAY_APPEND_ALLOC; + } + wapp_f128_array_copy_capped(array, output); + } + + wapp_f128_array_append_capped(output, item); + +RETURN_F128_ARRAY_APPEND_ALLOC: + return output; +} + +F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other) { + F128Array *output = array; + + if (!allocator || !array || !other) { + goto RETURN_F128_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_F128_ARRAY_EXTEND_ALLOC; + } + wapp_f128_array_copy_capped(array, output); + } + + wapp_f128_array_extend_capped(output, other); + +RETURN_F128_ARRAY_EXTEND_ALLOC: + return output; +} + +F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst) { + F128Array *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_F128_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_f128_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_F128_ARRAY_COPY_ALLOC; + } + } + + wapp_f128_array_clear(output); + wapp_f128_array_copy_capped(src, output); + +RETURN_F128_ARRAY_COPY_ALLOC: + return output; +} + +iptr *wapp_iptr_array_get(const IptrArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_iptr_array_append_capped(IptrArray *array, iptr item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + iptr *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_iptr_array_get(other, i); + if (!item) { + continue; + } + + wapp_iptr_array_append_capped(array, *item); + } +} + +void wapp_iptr_array_clear(IptrArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +iptr wapp_iptr_array_pop(IptrArray *array) { + if (!array || array->count == 0) { + return (iptr){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst) { + if (!src || !dst) { + return; + } + + wapp_iptr_array_clear(dst); + + iptr *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_iptr_array_get(src, i); + if (!item) { + continue; + } + + wapp_iptr_array_append_capped(dst, *item); + } +} + +IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(IptrArray) + sizeof(iptr) * capacity; + IptrArray *array = NULL; + + if (!allocator) { + goto RETURN_IPTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_IPTR_ARRAY_ALLOC; + } + + array->items = (iptr *)((u8 *)array + sizeof(IptrArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_IPTR_ARRAY_ALLOC: + return array; +} + +IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item) { + IptrArray *output = array; + + if (!allocator || !array) { + goto RETURN_IPTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_IPTR_ARRAY_APPEND_ALLOC; + } + wapp_iptr_array_copy_capped(array, output); + } + + wapp_iptr_array_append_capped(output, item); + +RETURN_IPTR_ARRAY_APPEND_ALLOC: + return output; +} + +IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other) { + IptrArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_IPTR_ARRAY_EXTEND_ALLOC; + } + wapp_iptr_array_copy_capped(array, output); + } + + wapp_iptr_array_extend_capped(output, other); + +RETURN_IPTR_ARRAY_EXTEND_ALLOC: + return output; +} + +IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst) { + IptrArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_IPTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_iptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_IPTR_ARRAY_COPY_ALLOC; + } + } + + wapp_iptr_array_clear(output); + wapp_iptr_array_copy_capped(src, output); + +RETURN_IPTR_ARRAY_COPY_ALLOC: + return output; +} + +uptr *wapp_uptr_array_get(const UptrArray *array, u64 index) { + if (!array || index >= array->count) { + return NULL; + } + + return &(array->items[index]); +} + +void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item) { + if (!array || index >= array->count) { + return; + } + + array->items[index] = item; +} + +void wapp_uptr_array_append_capped(UptrArray *array, uptr item) { + if (!array || array->count >= array->capacity) { + return; + } + + array->items[(array->count)++] = item; +} + +void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other) { + if (!array || !other) { + return; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + return; + } + + uptr *item; + u64 items_to_add = other->count; + for (u64 i = 0; i < items_to_add; ++i) { + item = wapp_uptr_array_get(other, i); + if (!item) { + continue; + } + + wapp_uptr_array_append_capped(array, *item); + } +} + +void wapp_uptr_array_clear(UptrArray *array) { + if (!array) { + return; + } + + array->count = 0; +} + +uptr wapp_uptr_array_pop(UptrArray *array) { + if (!array || array->count == 0) { + return (uptr){0}; + } + + return array->items[--(array->count)]; +} + +void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst) { + if (!src || !dst) { + return; + } + + wapp_uptr_array_clear(dst); + + uptr *item; + u64 to_copy = src->count < dst->capacity ? src->count : dst->capacity; + for (u64 i = 0; i < to_copy; ++i) { + item = wapp_uptr_array_get(src, i); + if (!item) { + continue; + } + + wapp_uptr_array_append_capped(dst, *item); + } +} + +UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity) { + u64 allocation_size = sizeof(UptrArray) + sizeof(uptr) * capacity; + UptrArray *array = NULL; + + if (!allocator) { + goto RETURN_UPTR_ARRAY_ALLOC; + } + + array = wapp_mem_allocator_alloc(allocator, allocation_size); + if (!array) { + goto RETURN_UPTR_ARRAY_ALLOC; + } + + array->items = (uptr *)((u8 *)array + sizeof(UptrArray)); + array->count = 0; + array->capacity = capacity; + +RETURN_UPTR_ARRAY_ALLOC: + return array; +} + +UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item) { + UptrArray *output = array; + + if (!allocator || !array) { + goto RETURN_UPTR_ARRAY_APPEND_ALLOC; + } + + if (array->count >= array->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_UPTR_ARRAY_APPEND_ALLOC; + } + wapp_uptr_array_copy_capped(array, output); + } + + wapp_uptr_array_append_capped(output, item); + +RETURN_UPTR_ARRAY_APPEND_ALLOC: + return output; +} + +UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other) { + UptrArray *output = array; + + if (!allocator || !array || !other) { + goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; + } + + u64 remaining_capacity = array->capacity - array->count; + if (other->count >= remaining_capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(array->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = array; + goto RETURN_UPTR_ARRAY_EXTEND_ALLOC; + } + wapp_uptr_array_copy_capped(array, output); + } + + wapp_uptr_array_extend_capped(output, other); + +RETURN_UPTR_ARRAY_EXTEND_ALLOC: + return output; +} + +UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst) { + UptrArray *output = dst; + + if (!allocator || !src || !dst) { + goto RETURN_UPTR_ARRAY_COPY_ALLOC; + } + + if (src->count >= dst->capacity) { + u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(dst->capacity * 2); + output = wapp_uptr_array_alloc_capacity(allocator, new_capacity); + if (!output) { + output = dst; + goto RETURN_UPTR_ARRAY_COPY_ALLOC; + } + } + + wapp_uptr_array_clear(output); + wapp_uptr_array_copy_capped(src, output); + +RETURN_UPTR_ARRAY_COPY_ALLOC: + return output; +} + diff --git a/src/primitives/array/array.h b/src/primitives/array/array.h new file mode 100644 index 0000000..70906b1 --- /dev/null +++ b/src/primitives/array/array.h @@ -0,0 +1,505 @@ +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + +#ifndef ARRAY_H +#define ARRAY_H + +#include "../mem_allocator/mem_allocator.h" +#include "../strings/str8/str8.h" +#include "../../common/misc/misc_utils.h" +#include "../../common/aliases/aliases.h" +#include "../../common/platform/platform.h" +#include + +#ifdef WAPP_PLATFORM_CPP +BEGIN_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#define wapp_str8_array(...) ((Str8Array){ \ + .items = (Str8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(Str8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(Str8, __VA_ARGS__) * 2) \ +}) +#define wapp_str8_array_with_capacity(CAPACITY) ((Str8Array){.items = (Str8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_void_ptr_array(...) ((VoidPArray){ \ + .items = (void *[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(void *, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(void *, __VA_ARGS__) * 2) \ +}) +#define wapp_void_ptr_array_with_capacity(CAPACITY) ((VoidPArray){.items = (void *[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_bool_array(...) ((BoolArray){ \ + .items = (bool[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(bool, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(bool, __VA_ARGS__) * 2) \ +}) +#define wapp_bool_array_with_capacity(CAPACITY) ((BoolArray){.items = (bool[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_char_array(...) ((CharArray){ \ + .items = (char[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(char, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(char, __VA_ARGS__) * 2) \ +}) +#define wapp_char_array_with_capacity(CAPACITY) ((CharArray){.items = (char[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c8_array(...) ((C8Array){ \ + .items = (c8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c8, __VA_ARGS__) * 2) \ +}) +#define wapp_c8_array_with_capacity(CAPACITY) ((C8Array){.items = (c8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c16_array(...) ((C16Array){ \ + .items = (c16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c16, __VA_ARGS__) * 2) \ +}) +#define wapp_c16_array_with_capacity(CAPACITY) ((C16Array){.items = (c16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_c32_array(...) ((C32Array){ \ + .items = (c32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(c32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(c32, __VA_ARGS__) * 2) \ +}) +#define wapp_c32_array_with_capacity(CAPACITY) ((C32Array){.items = (c32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i8_array(...) ((I8Array){ \ + .items = (i8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i8, __VA_ARGS__) * 2) \ +}) +#define wapp_i8_array_with_capacity(CAPACITY) ((I8Array){.items = (i8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i16_array(...) ((I16Array){ \ + .items = (i16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i16, __VA_ARGS__) * 2) \ +}) +#define wapp_i16_array_with_capacity(CAPACITY) ((I16Array){.items = (i16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i32_array(...) ((I32Array){ \ + .items = (i32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i32, __VA_ARGS__) * 2) \ +}) +#define wapp_i32_array_with_capacity(CAPACITY) ((I32Array){.items = (i32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_i64_array(...) ((I64Array){ \ + .items = (i64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(i64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(i64, __VA_ARGS__) * 2) \ +}) +#define wapp_i64_array_with_capacity(CAPACITY) ((I64Array){.items = (i64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u8_array(...) ((U8Array){ \ + .items = (u8[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u8, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u8, __VA_ARGS__) * 2) \ +}) +#define wapp_u8_array_with_capacity(CAPACITY) ((U8Array){.items = (u8[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u16_array(...) ((U16Array){ \ + .items = (u16[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u16, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u16, __VA_ARGS__) * 2) \ +}) +#define wapp_u16_array_with_capacity(CAPACITY) ((U16Array){.items = (u16[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u32_array(...) ((U32Array){ \ + .items = (u32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u32, __VA_ARGS__) * 2) \ +}) +#define wapp_u32_array_with_capacity(CAPACITY) ((U32Array){.items = (u32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_u64_array(...) ((U64Array){ \ + .items = (u64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(u64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(u64, __VA_ARGS__) * 2) \ +}) +#define wapp_u64_array_with_capacity(CAPACITY) ((U64Array){.items = (u64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f32_array(...) ((F32Array){ \ + .items = (f32[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f32, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f32, __VA_ARGS__) * 2) \ +}) +#define wapp_f32_array_with_capacity(CAPACITY) ((F32Array){.items = (f32[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f64_array(...) ((F64Array){ \ + .items = (f64[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f64, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f64, __VA_ARGS__) * 2) \ +}) +#define wapp_f64_array_with_capacity(CAPACITY) ((F64Array){.items = (f64[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_f128_array(...) ((F128Array){ \ + .items = (f128[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(f128, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(f128, __VA_ARGS__) * 2) \ +}) +#define wapp_f128_array_with_capacity(CAPACITY) ((F128Array){.items = (f128[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_iptr_array(...) ((IptrArray){ \ + .items = (iptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(iptr, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(iptr, __VA_ARGS__) * 2) \ +}) +#define wapp_iptr_array_with_capacity(CAPACITY) ((IptrArray){.items = (iptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) +#define wapp_uptr_array(...) ((UptrArray){ \ + .items = (uptr[wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2)]){__VA_ARGS__}, \ + .count = wapp_misc_utils_va_args_count(uptr, __VA_ARGS__), \ + .capacity = wapp_misc_utils_u64_round_up_pow2(wapp_misc_utils_va_args_count(uptr, __VA_ARGS__) * 2) \ +}) +#define wapp_uptr_array_with_capacity(CAPACITY) ((UptrArray){.items = (uptr[CAPACITY]){0}, .count = 0, .capacity = CAPACITY}) + +typedef struct Str8Array Str8Array; +struct Str8Array { + Str8 *items; + u64 count; + u64 capacity; +}; + +typedef struct VoidPArray VoidPArray; +struct VoidPArray { + void * *items; + u64 count; + u64 capacity; +}; + +typedef struct BoolArray BoolArray; +struct BoolArray { + bool *items; + u64 count; + u64 capacity; +}; + +typedef struct CharArray CharArray; +struct CharArray { + char *items; + u64 count; + u64 capacity; +}; + +typedef struct C8Array C8Array; +struct C8Array { + c8 *items; + u64 count; + u64 capacity; +}; + +typedef struct C16Array C16Array; +struct C16Array { + c16 *items; + u64 count; + u64 capacity; +}; + +typedef struct C32Array C32Array; +struct C32Array { + c32 *items; + u64 count; + u64 capacity; +}; + +typedef struct I8Array I8Array; +struct I8Array { + i8 *items; + u64 count; + u64 capacity; +}; + +typedef struct I16Array I16Array; +struct I16Array { + i16 *items; + u64 count; + u64 capacity; +}; + +typedef struct I32Array I32Array; +struct I32Array { + i32 *items; + u64 count; + u64 capacity; +}; + +typedef struct I64Array I64Array; +struct I64Array { + i64 *items; + u64 count; + u64 capacity; +}; + +typedef struct U8Array U8Array; +struct U8Array { + u8 *items; + u64 count; + u64 capacity; +}; + +typedef struct U16Array U16Array; +struct U16Array { + u16 *items; + u64 count; + u64 capacity; +}; + +typedef struct U32Array U32Array; +struct U32Array { + u32 *items; + u64 count; + u64 capacity; +}; + +typedef struct U64Array U64Array; +struct U64Array { + u64 *items; + u64 count; + u64 capacity; +}; + +typedef struct F32Array F32Array; +struct F32Array { + f32 *items; + u64 count; + u64 capacity; +}; + +typedef struct F64Array F64Array; +struct F64Array { + f64 *items; + u64 count; + u64 capacity; +}; + +typedef struct F128Array F128Array; +struct F128Array { + f128 *items; + u64 count; + u64 capacity; +}; + +typedef struct IptrArray IptrArray; +struct IptrArray { + iptr *items; + u64 count; + u64 capacity; +}; + +typedef struct UptrArray UptrArray; +struct UptrArray { + uptr *items; + u64 count; + u64 capacity; +}; + +Str8 *wapp_str8_array_get(const Str8Array *array, u64 index); +void wapp_str8_array_set(Str8Array *array, u64 index, Str8 item); +void wapp_str8_array_append_capped(Str8Array *array, Str8 item); +void wapp_str8_array_extend_capped(Str8Array *array, const Str8Array *other); +void wapp_str8_array_clear(Str8Array *array); +Str8 wapp_str8_array_pop(Str8Array *array); +void wapp_str8_array_copy_capped(const Str8Array *src, Str8Array *dst); +Str8Array *wapp_str8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +Str8Array *wapp_str8_array_append_alloc(const Allocator *allocator, Str8Array *array, Str8 item); +Str8Array *wapp_str8_array_extend_alloc(const Allocator *allocator, Str8Array *array, const Str8Array *other); +Str8Array *wapp_str8_array_copy_alloc(const Allocator *allocator, const Str8Array *src, Str8Array *dst); +void * *wapp_void_ptr_array_get(const VoidPArray *array, u64 index); +void wapp_void_ptr_array_set(VoidPArray *array, u64 index, void * item); +void wapp_void_ptr_array_append_capped(VoidPArray *array, void * item); +void wapp_void_ptr_array_extend_capped(VoidPArray *array, const VoidPArray *other); +void wapp_void_ptr_array_clear(VoidPArray *array); +void * wapp_void_ptr_array_pop(VoidPArray *array); +void wapp_void_ptr_array_copy_capped(const VoidPArray *src, VoidPArray *dst); +VoidPArray *wapp_void_ptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +VoidPArray *wapp_void_ptr_array_append_alloc(const Allocator *allocator, VoidPArray *array, void * item); +VoidPArray *wapp_void_ptr_array_extend_alloc(const Allocator *allocator, VoidPArray *array, const VoidPArray *other); +VoidPArray *wapp_void_ptr_array_copy_alloc(const Allocator *allocator, const VoidPArray *src, VoidPArray *dst); +bool *wapp_bool_array_get(const BoolArray *array, u64 index); +void wapp_bool_array_set(BoolArray *array, u64 index, bool item); +void wapp_bool_array_append_capped(BoolArray *array, bool item); +void wapp_bool_array_extend_capped(BoolArray *array, const BoolArray *other); +void wapp_bool_array_clear(BoolArray *array); +bool wapp_bool_array_pop(BoolArray *array); +void wapp_bool_array_copy_capped(const BoolArray *src, BoolArray *dst); +BoolArray *wapp_bool_array_alloc_capacity(const Allocator *allocator, u64 capacity); +BoolArray *wapp_bool_array_append_alloc(const Allocator *allocator, BoolArray *array, bool item); +BoolArray *wapp_bool_array_extend_alloc(const Allocator *allocator, BoolArray *array, const BoolArray *other); +BoolArray *wapp_bool_array_copy_alloc(const Allocator *allocator, const BoolArray *src, BoolArray *dst); +char *wapp_char_array_get(const CharArray *array, u64 index); +void wapp_char_array_set(CharArray *array, u64 index, char item); +void wapp_char_array_append_capped(CharArray *array, char item); +void wapp_char_array_extend_capped(CharArray *array, const CharArray *other); +void wapp_char_array_clear(CharArray *array); +char wapp_char_array_pop(CharArray *array); +void wapp_char_array_copy_capped(const CharArray *src, CharArray *dst); +CharArray *wapp_char_array_alloc_capacity(const Allocator *allocator, u64 capacity); +CharArray *wapp_char_array_append_alloc(const Allocator *allocator, CharArray *array, char item); +CharArray *wapp_char_array_extend_alloc(const Allocator *allocator, CharArray *array, const CharArray *other); +CharArray *wapp_char_array_copy_alloc(const Allocator *allocator, const CharArray *src, CharArray *dst); +c8 *wapp_c8_array_get(const C8Array *array, u64 index); +void wapp_c8_array_set(C8Array *array, u64 index, c8 item); +void wapp_c8_array_append_capped(C8Array *array, c8 item); +void wapp_c8_array_extend_capped(C8Array *array, const C8Array *other); +void wapp_c8_array_clear(C8Array *array); +c8 wapp_c8_array_pop(C8Array *array); +void wapp_c8_array_copy_capped(const C8Array *src, C8Array *dst); +C8Array *wapp_c8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C8Array *wapp_c8_array_append_alloc(const Allocator *allocator, C8Array *array, c8 item); +C8Array *wapp_c8_array_extend_alloc(const Allocator *allocator, C8Array *array, const C8Array *other); +C8Array *wapp_c8_array_copy_alloc(const Allocator *allocator, const C8Array *src, C8Array *dst); +c16 *wapp_c16_array_get(const C16Array *array, u64 index); +void wapp_c16_array_set(C16Array *array, u64 index, c16 item); +void wapp_c16_array_append_capped(C16Array *array, c16 item); +void wapp_c16_array_extend_capped(C16Array *array, const C16Array *other); +void wapp_c16_array_clear(C16Array *array); +c16 wapp_c16_array_pop(C16Array *array); +void wapp_c16_array_copy_capped(const C16Array *src, C16Array *dst); +C16Array *wapp_c16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C16Array *wapp_c16_array_append_alloc(const Allocator *allocator, C16Array *array, c16 item); +C16Array *wapp_c16_array_extend_alloc(const Allocator *allocator, C16Array *array, const C16Array *other); +C16Array *wapp_c16_array_copy_alloc(const Allocator *allocator, const C16Array *src, C16Array *dst); +c32 *wapp_c32_array_get(const C32Array *array, u64 index); +void wapp_c32_array_set(C32Array *array, u64 index, c32 item); +void wapp_c32_array_append_capped(C32Array *array, c32 item); +void wapp_c32_array_extend_capped(C32Array *array, const C32Array *other); +void wapp_c32_array_clear(C32Array *array); +c32 wapp_c32_array_pop(C32Array *array); +void wapp_c32_array_copy_capped(const C32Array *src, C32Array *dst); +C32Array *wapp_c32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +C32Array *wapp_c32_array_append_alloc(const Allocator *allocator, C32Array *array, c32 item); +C32Array *wapp_c32_array_extend_alloc(const Allocator *allocator, C32Array *array, const C32Array *other); +C32Array *wapp_c32_array_copy_alloc(const Allocator *allocator, const C32Array *src, C32Array *dst); +i8 *wapp_i8_array_get(const I8Array *array, u64 index); +void wapp_i8_array_set(I8Array *array, u64 index, i8 item); +void wapp_i8_array_append_capped(I8Array *array, i8 item); +void wapp_i8_array_extend_capped(I8Array *array, const I8Array *other); +void wapp_i8_array_clear(I8Array *array); +i8 wapp_i8_array_pop(I8Array *array); +void wapp_i8_array_copy_capped(const I8Array *src, I8Array *dst); +I8Array *wapp_i8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I8Array *wapp_i8_array_append_alloc(const Allocator *allocator, I8Array *array, i8 item); +I8Array *wapp_i8_array_extend_alloc(const Allocator *allocator, I8Array *array, const I8Array *other); +I8Array *wapp_i8_array_copy_alloc(const Allocator *allocator, const I8Array *src, I8Array *dst); +i16 *wapp_i16_array_get(const I16Array *array, u64 index); +void wapp_i16_array_set(I16Array *array, u64 index, i16 item); +void wapp_i16_array_append_capped(I16Array *array, i16 item); +void wapp_i16_array_extend_capped(I16Array *array, const I16Array *other); +void wapp_i16_array_clear(I16Array *array); +i16 wapp_i16_array_pop(I16Array *array); +void wapp_i16_array_copy_capped(const I16Array *src, I16Array *dst); +I16Array *wapp_i16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I16Array *wapp_i16_array_append_alloc(const Allocator *allocator, I16Array *array, i16 item); +I16Array *wapp_i16_array_extend_alloc(const Allocator *allocator, I16Array *array, const I16Array *other); +I16Array *wapp_i16_array_copy_alloc(const Allocator *allocator, const I16Array *src, I16Array *dst); +i32 *wapp_i32_array_get(const I32Array *array, u64 index); +void wapp_i32_array_set(I32Array *array, u64 index, i32 item); +void wapp_i32_array_append_capped(I32Array *array, i32 item); +void wapp_i32_array_extend_capped(I32Array *array, const I32Array *other); +void wapp_i32_array_clear(I32Array *array); +i32 wapp_i32_array_pop(I32Array *array); +void wapp_i32_array_copy_capped(const I32Array *src, I32Array *dst); +I32Array *wapp_i32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I32Array *wapp_i32_array_append_alloc(const Allocator *allocator, I32Array *array, i32 item); +I32Array *wapp_i32_array_extend_alloc(const Allocator *allocator, I32Array *array, const I32Array *other); +I32Array *wapp_i32_array_copy_alloc(const Allocator *allocator, const I32Array *src, I32Array *dst); +i64 *wapp_i64_array_get(const I64Array *array, u64 index); +void wapp_i64_array_set(I64Array *array, u64 index, i64 item); +void wapp_i64_array_append_capped(I64Array *array, i64 item); +void wapp_i64_array_extend_capped(I64Array *array, const I64Array *other); +void wapp_i64_array_clear(I64Array *array); +i64 wapp_i64_array_pop(I64Array *array); +void wapp_i64_array_copy_capped(const I64Array *src, I64Array *dst); +I64Array *wapp_i64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +I64Array *wapp_i64_array_append_alloc(const Allocator *allocator, I64Array *array, i64 item); +I64Array *wapp_i64_array_extend_alloc(const Allocator *allocator, I64Array *array, const I64Array *other); +I64Array *wapp_i64_array_copy_alloc(const Allocator *allocator, const I64Array *src, I64Array *dst); +u8 *wapp_u8_array_get(const U8Array *array, u64 index); +void wapp_u8_array_set(U8Array *array, u64 index, u8 item); +void wapp_u8_array_append_capped(U8Array *array, u8 item); +void wapp_u8_array_extend_capped(U8Array *array, const U8Array *other); +void wapp_u8_array_clear(U8Array *array); +u8 wapp_u8_array_pop(U8Array *array); +void wapp_u8_array_copy_capped(const U8Array *src, U8Array *dst); +U8Array *wapp_u8_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U8Array *wapp_u8_array_append_alloc(const Allocator *allocator, U8Array *array, u8 item); +U8Array *wapp_u8_array_extend_alloc(const Allocator *allocator, U8Array *array, const U8Array *other); +U8Array *wapp_u8_array_copy_alloc(const Allocator *allocator, const U8Array *src, U8Array *dst); +u16 *wapp_u16_array_get(const U16Array *array, u64 index); +void wapp_u16_array_set(U16Array *array, u64 index, u16 item); +void wapp_u16_array_append_capped(U16Array *array, u16 item); +void wapp_u16_array_extend_capped(U16Array *array, const U16Array *other); +void wapp_u16_array_clear(U16Array *array); +u16 wapp_u16_array_pop(U16Array *array); +void wapp_u16_array_copy_capped(const U16Array *src, U16Array *dst); +U16Array *wapp_u16_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U16Array *wapp_u16_array_append_alloc(const Allocator *allocator, U16Array *array, u16 item); +U16Array *wapp_u16_array_extend_alloc(const Allocator *allocator, U16Array *array, const U16Array *other); +U16Array *wapp_u16_array_copy_alloc(const Allocator *allocator, const U16Array *src, U16Array *dst); +u32 *wapp_u32_array_get(const U32Array *array, u64 index); +void wapp_u32_array_set(U32Array *array, u64 index, u32 item); +void wapp_u32_array_append_capped(U32Array *array, u32 item); +void wapp_u32_array_extend_capped(U32Array *array, const U32Array *other); +void wapp_u32_array_clear(U32Array *array); +u32 wapp_u32_array_pop(U32Array *array); +void wapp_u32_array_copy_capped(const U32Array *src, U32Array *dst); +U32Array *wapp_u32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U32Array *wapp_u32_array_append_alloc(const Allocator *allocator, U32Array *array, u32 item); +U32Array *wapp_u32_array_extend_alloc(const Allocator *allocator, U32Array *array, const U32Array *other); +U32Array *wapp_u32_array_copy_alloc(const Allocator *allocator, const U32Array *src, U32Array *dst); +u64 *wapp_u64_array_get(const U64Array *array, u64 index); +void wapp_u64_array_set(U64Array *array, u64 index, u64 item); +void wapp_u64_array_append_capped(U64Array *array, u64 item); +void wapp_u64_array_extend_capped(U64Array *array, const U64Array *other); +void wapp_u64_array_clear(U64Array *array); +u64 wapp_u64_array_pop(U64Array *array); +void wapp_u64_array_copy_capped(const U64Array *src, U64Array *dst); +U64Array *wapp_u64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +U64Array *wapp_u64_array_append_alloc(const Allocator *allocator, U64Array *array, u64 item); +U64Array *wapp_u64_array_extend_alloc(const Allocator *allocator, U64Array *array, const U64Array *other); +U64Array *wapp_u64_array_copy_alloc(const Allocator *allocator, const U64Array *src, U64Array *dst); +f32 *wapp_f32_array_get(const F32Array *array, u64 index); +void wapp_f32_array_set(F32Array *array, u64 index, f32 item); +void wapp_f32_array_append_capped(F32Array *array, f32 item); +void wapp_f32_array_extend_capped(F32Array *array, const F32Array *other); +void wapp_f32_array_clear(F32Array *array); +f32 wapp_f32_array_pop(F32Array *array); +void wapp_f32_array_copy_capped(const F32Array *src, F32Array *dst); +F32Array *wapp_f32_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F32Array *wapp_f32_array_append_alloc(const Allocator *allocator, F32Array *array, f32 item); +F32Array *wapp_f32_array_extend_alloc(const Allocator *allocator, F32Array *array, const F32Array *other); +F32Array *wapp_f32_array_copy_alloc(const Allocator *allocator, const F32Array *src, F32Array *dst); +f64 *wapp_f64_array_get(const F64Array *array, u64 index); +void wapp_f64_array_set(F64Array *array, u64 index, f64 item); +void wapp_f64_array_append_capped(F64Array *array, f64 item); +void wapp_f64_array_extend_capped(F64Array *array, const F64Array *other); +void wapp_f64_array_clear(F64Array *array); +f64 wapp_f64_array_pop(F64Array *array); +void wapp_f64_array_copy_capped(const F64Array *src, F64Array *dst); +F64Array *wapp_f64_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F64Array *wapp_f64_array_append_alloc(const Allocator *allocator, F64Array *array, f64 item); +F64Array *wapp_f64_array_extend_alloc(const Allocator *allocator, F64Array *array, const F64Array *other); +F64Array *wapp_f64_array_copy_alloc(const Allocator *allocator, const F64Array *src, F64Array *dst); +f128 *wapp_f128_array_get(const F128Array *array, u64 index); +void wapp_f128_array_set(F128Array *array, u64 index, f128 item); +void wapp_f128_array_append_capped(F128Array *array, f128 item); +void wapp_f128_array_extend_capped(F128Array *array, const F128Array *other); +void wapp_f128_array_clear(F128Array *array); +f128 wapp_f128_array_pop(F128Array *array); +void wapp_f128_array_copy_capped(const F128Array *src, F128Array *dst); +F128Array *wapp_f128_array_alloc_capacity(const Allocator *allocator, u64 capacity); +F128Array *wapp_f128_array_append_alloc(const Allocator *allocator, F128Array *array, f128 item); +F128Array *wapp_f128_array_extend_alloc(const Allocator *allocator, F128Array *array, const F128Array *other); +F128Array *wapp_f128_array_copy_alloc(const Allocator *allocator, const F128Array *src, F128Array *dst); +iptr *wapp_iptr_array_get(const IptrArray *array, u64 index); +void wapp_iptr_array_set(IptrArray *array, u64 index, iptr item); +void wapp_iptr_array_append_capped(IptrArray *array, iptr item); +void wapp_iptr_array_extend_capped(IptrArray *array, const IptrArray *other); +void wapp_iptr_array_clear(IptrArray *array); +iptr wapp_iptr_array_pop(IptrArray *array); +void wapp_iptr_array_copy_capped(const IptrArray *src, IptrArray *dst); +IptrArray *wapp_iptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +IptrArray *wapp_iptr_array_append_alloc(const Allocator *allocator, IptrArray *array, iptr item); +IptrArray *wapp_iptr_array_extend_alloc(const Allocator *allocator, IptrArray *array, const IptrArray *other); +IptrArray *wapp_iptr_array_copy_alloc(const Allocator *allocator, const IptrArray *src, IptrArray *dst); +uptr *wapp_uptr_array_get(const UptrArray *array, u64 index); +void wapp_uptr_array_set(UptrArray *array, u64 index, uptr item); +void wapp_uptr_array_append_capped(UptrArray *array, uptr item); +void wapp_uptr_array_extend_capped(UptrArray *array, const UptrArray *other); +void wapp_uptr_array_clear(UptrArray *array); +uptr wapp_uptr_array_pop(UptrArray *array); +void wapp_uptr_array_copy_capped(const UptrArray *src, UptrArray *dst); +UptrArray *wapp_uptr_array_alloc_capacity(const Allocator *allocator, u64 capacity); +UptrArray *wapp_uptr_array_append_alloc(const Allocator *allocator, UptrArray *array, uptr item); +UptrArray *wapp_uptr_array_extend_alloc(const Allocator *allocator, UptrArray *array, const UptrArray *other); +UptrArray *wapp_uptr_array_copy_alloc(const Allocator *allocator, const UptrArray *src, UptrArray *dst); + +#ifdef WAPP_PLATFORM_CPP +END_C_LINKAGE +#endif // !WAPP_PLATFORM_CPP + +#endif // !ARRAY_H