#pragma once #include "../std.h" typedef struct List { void* data; u32 size; u32 allocated_size; } List; #define List_construct(L, T, OCCUPIED_COUNT, ALLOCATED_COUNT) \ List_construct_size(L, (OCCUPIED_COUNT) * sizeof(T), (ALLOCATED_COUNT) * sizeof(T)) static inline List List_construct_size(void* data_ptr, u32 size, u32 allocated_size) { return (List){ .data = data_ptr, .size = size, .allocated_size = allocated_size }; } #define List_alloc(L, T, INITIAL_COUNT) List_alloc_size(L, (INITIAL_COUNT) * sizeof(T)) List List_alloc_size(u32 initial_size); void* List_expand(List* ptr, u32 expansion_size); #define List_push(L, T, VALUE) *(T*)(List_expand(L, sizeof(T))) = VALUE #define List_pushMany(L, T, VALUES_PTR, COUNT) List_push_size(L, VALUES_PTR, (COUNT) * sizeof(T)) void List_push_size(List* ptr, void* values, u32 size); #define List_removeAt(L, T, I, COUNT) List_removeAt_size(L, (I)*sizeof(T), (COUNT) * sizeof(T)) bool List_removeAt_size(List* ptr, u32 i, u32 remove_size); #define List_len(L, T) ((L)->size / sizeof(T))