Mercurial > ~dholland > hg > ag > index.cgi
comparison help2html/array.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children | 60b08b68c750 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 #include <assert.h> | |
2 | |
3 /* treat as opaque */ | |
4 struct array { | |
5 void **v; | |
6 unsigned num, max; | |
7 }; | |
8 | |
9 struct array *array_create(void); | |
10 void array_init(struct array *a); | |
11 void array_cleanup(struct array *a); | |
12 void array_destroy(struct array *a); | |
13 | |
14 unsigned array_num(const struct array *a); | |
15 void *array_get(const struct array *a, unsigned ix); | |
16 void array_set(struct array *a, unsigned ix, void *ptr); | |
17 unsigned array_add(struct array *a, void *ptr); | |
18 void array_setsize(struct array *a, unsigned newsize); | |
19 | |
20 /* compact, removing any null elements */ | |
21 void array_nonulls(struct array *a); | |
22 | |
23 /* x and y are pointers that were placed in the array */ | |
24 void array_sort(struct array *a, int (*f)(void *x, void *y)); | |
25 | |
26 extern inline unsigned array_num(const struct array *a) { | |
27 return a->num; | |
28 } | |
29 | |
30 extern inline void *array_get(const struct array *a, unsigned ix) { | |
31 assert(ix < a->num); | |
32 return a->v[ix]; | |
33 } | |
34 | |
35 extern inline void array_set(struct array *a, unsigned ix, void *ptr) { | |
36 assert(ix < a->num); | |
37 a->v[ix] = ptr; | |
38 } |