Add missing word
[vis.git] / array.h
blob2d9c1231ec1ee2618ef5e371e3e49f57eec9ccb4
1 #ifndef ARRAY_H
2 #define ARRAY_H
4 #include <stddef.h>
5 #include <stdbool.h>
7 typedef struct { /* a dynamically growing array */
8 void **items; /* NULL if empty */
9 size_t len; /* number of currently stored items */
10 size_t count; /* maximal capacity of the array */
11 } Array;
13 /* initalize a (stack allocated) Array instance */
14 void array_init(Array*);
15 /* release/free the storage space used to hold items, reset size to zero */
16 void array_release(Array*);
17 /* like above but also call free(3) for each stored pointer */
18 void array_release_full(Array*);
19 /* remove all elements, set array length to zero, keep allocated memory */
20 void array_clear(Array*);
21 /* reserve space to store at least `count' elements in this aray */
22 bool array_reserve(Array*, size_t count);
23 /* get/set the i-th (zero based) element of the array */
24 void *array_get(Array*, size_t idx);
25 bool array_set(Array*, size_t idx, void *item);
26 /* add a new element to the end of the array */
27 bool array_add(Array*, void *item);
28 /* return the number of elements currently stored in the array */
29 size_t array_length(Array*);
31 #endif