view help2html/array.h @ 8:ec2b657edf13

Add explicit lint-comment-style fallthrough annotations. GCC now assumes that if you don't have these you're making a mistake, which is annoying. XXX: This changeset updates the AG output files only (by hand) and is XXX: abusive - rebuilding them will erase the change. However, I need XXX: to get things to build before I can try to get AG to issue the XXX: annotations itself, so this seems like a reasonable expedient.
author David A. Holland
date Mon, 30 May 2022 23:51:43 -0400 (2022-05-31)
parents 13d2b8934445
children 60b08b68c750
line wrap: on
line source
#include <assert.h>

/* treat as opaque */
struct array {
   void **v;
   unsigned num, max;
};

struct array *array_create(void);
void array_init(struct array *a);
void array_cleanup(struct array *a);
void array_destroy(struct array *a);

unsigned array_num(const struct array *a);
void *array_get(const struct array *a, unsigned ix);
void array_set(struct array *a, unsigned ix, void *ptr);
unsigned array_add(struct array *a, void *ptr);
void array_setsize(struct array *a, unsigned newsize);

/* compact, removing any null elements */
void array_nonulls(struct array *a);

/* x and y are pointers that were placed in the array */
void array_sort(struct array *a, int (*f)(void *x, void *y));

extern inline unsigned array_num(const struct array *a) {
   return a->num;
}

extern inline void *array_get(const struct array *a, unsigned ix) {
   assert(ix < a->num);
   return a->v[ix];
}

extern inline void array_set(struct array *a, unsigned ix, void *ptr) {
   assert(ix < a->num);
   a->v[ix] = ptr;
}