comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 #include <assert.h>
2
3 /* treat as opaque */
4 struct uintarray {
5 unsigned *v;
6 unsigned num, max;
7 };
8
9 struct uintarray *uintarray_create(void);
10 void uintarray_init(struct uintarray *a);
11 void uintarray_cleanup(struct uintarray *a);
12 void uintarray_destroy(struct uintarray *a);
13
14 unsigned uintarray_num(const struct uintarray *a);
15 unsigned uintarray_get(const struct uintarray *a, unsigned ix);
16 void uintarray_set(struct uintarray *a, unsigned ix, unsigned val);
17 void uintarray_add(struct uintarray *a, unsigned val);
18 void uintarray_setsize(struct uintarray *a, unsigned newsize);
19
20 /* x and y are pointers that were placed in the uintarray */
21 void uintarray_sort(struct uintarray *a, int (*f)(unsigned x, unsigned y));
22
23 extern inline unsigned uintarray_num(const struct uintarray *a) {
24 return a->num;
25 }
26
27 extern inline unsigned uintarray_get(const struct uintarray *a, unsigned ix) {
28 assert(ix < a->num);
29 return a->v[ix];
30 }
31
32 extern inline void uintarray_set(struct uintarray *a, unsigned ix,
33 unsigned val) {
34 assert(ix < a->num);
35 a->v[ix] = val;
36 }