summaryrefslogtreecommitdiff
path: root/src/libdatastruct/genset_iter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libdatastruct/genset_iter.c')
-rw-r--r--src/libdatastruct/genset_iter.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libdatastruct/genset_iter.c b/src/libdatastruct/genset_iter.c
new file mode 100644
index 0000000..cc6e863
--- /dev/null
+++ b/src/libdatastruct/genset_iter.c
@@ -0,0 +1,19 @@
+/* ISC license. */
+
+#include <skalibs/bitarray.h>
+#include <skalibs/functypes.h>
+#include <skalibs/genset.h>
+
+unsigned int genset_iter (genset_ref g, iterfunc_t_ref f, void *stuff)
+{
+ unsigned char bits[bitarray_div8(g->max)] ;
+ unsigned int i = 0, j = 0, n = 0, m = genset_n(g) ;
+ bitarray_setn(bits, 0, g->max) ;
+ for (; i < g->sp ; i++) bitarray_clear(bits, g->freelist[i]) ;
+ for (i = 0 ; (i < g->max) && (j < m) ; i++) if (bitarray_peek(bits, i))
+ {
+ j++ ;
+ if ((*f)(g->storage + i * g->esize, stuff)) n++ ;
+ }
+ return n ;
+}