blob: 5f81798bfd3c66a8bf83f5ed65db786db10631f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
// SPDX-FileCopyrightText: 2024 Lizzy Fleckenstein <lizzy@vlhl.dev>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
#ifndef ARRAY_H
#define ARRAY_H
#include <stddef.h>
#define len(X) (sizeof X / sizeof *X)
#define array(T) struct { size_t len; T *data; }
#define arraybuf(T) struct { size_t cap; size_t len; T *data; }
#define ARR_REMOVE(A, P) memmove((P), (P)+1, sizeof *(P) * (--(A).len - ((P) - (A).data)));
#define ARR_APPEND(A) (((A).cap == (A).len) \
? (A).data = realloc((A).data, sizeof *(A).data * ((A).cap = (A).cap ? (A).cap * 2 : 1)) \
: NULL, &((A).data)[(A).len++])
#endif
|