aboutsummaryrefslogtreecommitdiff
path: root/include/vector.h
blob: fc0eb4cf680629d162eefa3c98bf8179297c70e4 (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
28
29
#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_pop(struct vector *);

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