-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvector.h
35 lines (29 loc) · 962 Bytes
/
vector.h
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
30
31
32
33
34
35
/*
Original vector implementation from Emil Hernvall.
Distributed under MIT license.
URL: https://gist.github.com/EmilHernvall/953968
*/
#ifndef VECTOR_H
#define VECTOR_H
#define VECTOR_INIT_CAPACITY 200
#define VECTOR_INIT(vec) vector vec; vector_init(&vec)
#define VECTOR_ADD(vec, item) vector_add(&vec, (void *) item)
#define VECTOR_SET(vec, id, item) vector_set(&vec, id, (void *) item)
#define VECTOR_GET(vec, type, id) (type) vector_get(&vec, id)
#define VECTOR_DELETE(vec, id) vector_delete(&vec, id)
#define VECTOR_TOTAL(vec) vector_total(&vec)
#define VECTOR_FREE(vec) vector_free(&vec)
typedef struct vector {
void **items;
int capacity;
int total;
} vector;
void vector_init(vector *);
int vector_total(vector *);
static void vector_resize(vector *, int);
void vector_add(vector *, void *);
void vector_set(vector *, int, void *);
void *vector_get(vector *, int);
void vector_delete(vector *, int);
void vector_free(vector *);
#endif