view help2html/array.h @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -0400
parents 60b08b68c750
children
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);

static inline unsigned array_num(const struct array *a);
static inline void *array_get(const struct array *a, unsigned ix);
static inline 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));

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

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

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