32 lines
1.2 KiB
C
Executable File
32 lines
1.2 KiB
C
Executable File
#pragma once
|
|
#include "../std.h"
|
|
|
|
#define List(T) List_
|
|
|
|
typedef struct List_ {
|
|
void* data;
|
|
u32 size;
|
|
u32 allocated_size;
|
|
} List_;
|
|
|
|
#define List_construct(T, DATA_PTR, OCCUPIED_COUNT, ALLOCATED_COUNT) \
|
|
List_construct_size(DATA_PTR, (OCCUPIED_COUNT) * sizeof(T), (ALLOCATED_COUNT) * sizeof(T))
|
|
|
|
static inline List_ List_construct_size(void* data_ptr, u32 occupied_size, u32 allocated_size) {
|
|
return (List_){ .data = data_ptr, .size = occupied_size, .allocated_size = allocated_size };
|
|
}
|
|
|
|
#define List_alloc(T, INITIAL_COUNT) List_alloc_size((INITIAL_COUNT) * sizeof(T))
|
|
List_ List_alloc_size(u32 initial_size);
|
|
|
|
void* List_expand_size(List_* ptr, u32 expansion_size);
|
|
#define List_push(L, T, VALUE) *(T*)(List_expand_size(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))
|
|
#define List_castTo_Array(l) Array_construct_size(l.data, l.size)
|