blob: a34ecea445e4d7782e30a2f22b1f64899fa86865 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#ifndef VECTOR_H
#define VECTOR_H
#include <stdlib.h>
#include <stdbool.h>
#include <sys/types.h>
#define VEC_CAP 32
struct vector {
size_t cap;
size_t len;
void **values;
};
struct vector *vector_new_with_cap(size_t cap);
#define vector_new() vector_new_with_cap(VEC_CAP)
ssize_t vector_push(struct vector *, void *val);
void vector_free(struct vector *);
#define vector_foreach(vec, i, val) \
for (i = 0, val = vec->values[i]; i < vec->len; i++, val = vec->values[i])
#endif
|