1 /* ISC license. */
2 
3 #ifndef GENSET_H
4 #define GENSET_H
5 
6 #include <stdint.h>
7 #include <skalibs/functypes.h>
8 
9 typedef struct genset_s genset, *genset_ref ;
10 struct genset_s
11 {
12   char *storage ;
13   uint32_t *freelist ;
14   uint32_t esize ;
15   uint32_t max ;
16   uint32_t sp ;
17 } ;
18 
19 #define GENSET_ZERO { .storage = 0, .freelist = 0, .esize = 1, .max = 0, .sp = 0 }
20 extern void genset_init (genset *, void *, uint32_t *, uint32_t, uint32_t) ;
21 #define GENSET_init(g, type, storage, fl, size) genset_init(g, storage, fl, sizeof(type), size)
22 
23 #define genset_p(type, g, i) ((type *)((g)->storage + (i) * (g)->esize))
24 extern uint32_t genset_new (genset *) ;
25 extern int genset_delete (genset *, uint32_t) ;
26 #define genset_n(g) ((g)->max - (g)->sp)
27 extern uint32_t genset_iter_nocancel (genset *, uint32_t, iterfunc_t_ref, void *) ;
28 #define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff)
29 extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ;
30 extern void genset_deepfree (genset *, freefunc_t_ref) ;
31 
32 #define GENSETB_TYPE(type, size) struct { type storage[size] ; uint32_t freelist[size] ; genset info ; }
33 #define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size)
34 #define gensetb_p(type, g, i) genset_p(type, &(g)->info, i)
35 #define gensetb_new(g) genset_new(&(g)->info)
36 #define gensetb_delete(g, i) genset_delete(&(g)->info, i)
37 #define gensetb_n(g) genset_n(&(g)->info)
38 #define gensetb_iter(g, f, p) genset_iter(&(g)->info, f, p)
39 #define gensetb_deepfree(g, f) genset_deepfree(&(g)->info, f)
40 
41 #endif
42