summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-04-13 02:19:08 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-04-13 02:19:08 +0000
commit57459439db1f48dbbace1ab059117798fa26d203 (patch)
tree537c15504b977b30af126ff4f9425c690672dc93 /src
parent564c6ba2f899a4b530d58f6ac123e31d6b797fe2 (diff)
downloadskalibs-57459439db1f48dbbace1ab059117798fa26d203.tar.xz
Add genset[dyn]_deepfree
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/genset.h2
-rw-r--r--src/include/skalibs/gensetdyn.h1
-rw-r--r--src/libdatastruct/genset_deepfree.c16
-rw-r--r--src/libdatastruct/gensetdyn_deepfree.c17
4 files changed, 36 insertions, 0 deletions
diff --git a/src/include/skalibs/genset.h b/src/include/skalibs/genset.h
index 9241d1a..fc14d24 100644
--- a/src/include/skalibs/genset.h
+++ b/src/include/skalibs/genset.h
@@ -27,6 +27,7 @@ extern int genset_delete (genset *, uint32_t) ;
extern uint32_t genset_iter_nocancel (genset *, uint32_t, iterfunc_t_ref, void *) ;
#define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff)
extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ;
+extern void genset_deepfree (genset *, freefunc_t_ref) ;
#define GENSETB_TYPE(type, size) struct { type storage[size] ; uint32_t freelist[size] ; genset info ; }
#define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size)
@@ -35,5 +36,6 @@ extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, voi
#define gensetb_delete(g, i) genset_delete(&(g)->info, i)
#define gensetb_n(g) genset_n(&(g)->info)
#define gensetb_iter(g, f, p) genset_iter(&(g)->info, f, p)
+#define gensetb_deepfree(g, f) genset_deepfree(&(g)->info, f)
#endif
diff --git a/src/include/skalibs/gensetdyn.h b/src/include/skalibs/gensetdyn.h
index f851ae7..c91a435 100644
--- a/src/include/skalibs/gensetdyn.h
+++ b/src/include/skalibs/gensetdyn.h
@@ -29,6 +29,7 @@ extern void gensetdyn_init (gensetdyn *, uint32_t, uint32_t, uint32_t, uint32_t)
extern int gensetdyn_ready (gensetdyn *, uint32_t) ;
#define gensetdyn_readyplus(x, n) gensetdyn_ready(x, gensetdyn_n(x) + (n))
extern void gensetdyn_free (gensetdyn *) ;
+extern void gensetdyn_deepfree (gensetdyn *, freefunc_t_ref) ;
extern int gensetdyn_new (gensetdyn *, uint32_t *) ;
extern int gensetdyn_delete (gensetdyn *, uint32_t) ;
diff --git a/src/libdatastruct/genset_deepfree.c b/src/libdatastruct/genset_deepfree.c
new file mode 100644
index 0000000..e219344
--- /dev/null
+++ b/src/libdatastruct/genset_deepfree.c
@@ -0,0 +1,16 @@
+/* ISC license. */
+
+#include <skalibs/functypes.h>
+#include <skalibs/genset.h>
+
+static int freeiter (char *s, void *aux)
+{
+ freefunc_t_ref f = aux ;
+ (*f)((void *)s) ;
+ return 1 ;
+}
+
+void genset_deepfree (genset *g, freefunc_t_ref f)
+{
+ genset_iter(g, &freeiter, f) ;
+}
diff --git a/src/libdatastruct/gensetdyn_deepfree.c b/src/libdatastruct/gensetdyn_deepfree.c
new file mode 100644
index 0000000..8822bc3
--- /dev/null
+++ b/src/libdatastruct/gensetdyn_deepfree.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/functypes.h>
+#include <skalibs/gensetdyn.h>
+
+static int freeiter (char *s, void *aux)
+{
+ freefunc_t_ref f = aux ;
+ (*f)((void *)s) ;
+ return 1 ;
+}
+
+void gensetdyn_deepfree (gensetdyn *g, freefunc_t_ref f)
+{
+ gensetdyn_iter(g, &freeiter, f) ;
+ gensetdyn_free(g) ;
+}