10 void array_init(Array
*arr
) {
11 memset(arr
, 0, sizeof *arr
);
14 bool array_reserve(Array
*arr
, size_t count
) {
15 if (count
< ARRAY_SIZE
)
17 if (arr
->count
< count
) {
18 count
= MAX(count
, arr
->count
*2);
19 void **items
= realloc(arr
->items
, count
* sizeof(void*));
28 void array_release(Array
*arr
) {
35 void array_release_full(Array
*arr
) {
38 for (size_t i
= 0; i
< arr
->len
; i
++)
43 void array_clear(Array
*arr
) {
46 memset(arr
->items
, 0, arr
->count
* sizeof(void*));
49 void *array_get(Array
*arr
, size_t idx
) {
50 if (idx
>= arr
->len
) {
54 return arr
->items
[idx
];
57 bool array_set(Array
*arr
, size_t idx
, void *item
) {
58 if (idx
>= arr
->len
) {
62 arr
->items
[idx
] = item
;
66 bool array_add(Array
*arr
, void *item
) {
67 if (!array_reserve(arr
, arr
->len
+1))
69 arr
->items
[arr
->len
++] = item
;;
73 size_t array_length(Array
*arr
) {