summaryrefslogtreecommitdiff
path: root/src/libdatastruct/genset_iter.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
commit3534b428629be185e096be99e3bd5fdfe32d5544 (patch)
tree210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libdatastruct/genset_iter.c
downloadskalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz
initial commit with rc for skalibs-2.0.0.0
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 ;
+}