Mercurial > ~dholland > hg > ag > index.cgi
diff help2html/uintarray.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/help2html/uintarray.h Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,36 @@ +#include <assert.h> + +/* treat as opaque */ +struct uintarray { + unsigned *v; + unsigned num, max; +}; + +struct uintarray *uintarray_create(void); +void uintarray_init(struct uintarray *a); +void uintarray_cleanup(struct uintarray *a); +void uintarray_destroy(struct uintarray *a); + +unsigned uintarray_num(const struct uintarray *a); +unsigned uintarray_get(const struct uintarray *a, unsigned ix); +void uintarray_set(struct uintarray *a, unsigned ix, unsigned val); +void uintarray_add(struct uintarray *a, unsigned val); +void uintarray_setsize(struct uintarray *a, unsigned newsize); + +/* x and y are pointers that were placed in the uintarray */ +void uintarray_sort(struct uintarray *a, int (*f)(unsigned x, unsigned y)); + +extern inline unsigned uintarray_num(const struct uintarray *a) { + return a->num; +} + +extern inline unsigned uintarray_get(const struct uintarray *a, unsigned ix) { + assert(ix < a->num); + return a->v[ix]; +} + +extern inline void uintarray_set(struct uintarray *a, unsigned ix, + unsigned val) { + assert(ix < a->num); + a->v[ix] = val; +}