view help2html/uintarray.h @ 20:bb115deb6fb2

Improve agfiles rule. (1) It didn't depend on $(AGCL) and it absolutely should have. (2) allow AGFORCE=1 to make it rebuild whether or not it looks out of date. (3) Document this.
author David A. Holland
date Mon, 13 Jun 2022 00:02:15 -0400
parents 60b08b68c750
children
line wrap: on
line source

#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);

static inline unsigned uintarray_num(const struct uintarray *a);
static inline unsigned uintarray_get(const struct uintarray *a, unsigned ix);
static inline 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));

static inline unsigned uintarray_num(const struct uintarray *a) {
   return a->num;
}

static inline unsigned uintarray_get(const struct uintarray *a, unsigned ix) {
   assert(ix < a->num);
   return a->v[ix];
}

static inline void uintarray_set(struct uintarray *a, unsigned ix, 
				 unsigned val) {
   assert(ix < a->num);
   a->v[ix] = val;
}