diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-09 16:10:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-01-09 16:10:40 +0000 |
commit | b59ce39f9779cf4b1ad423783b6a532f94a8e880 (patch) | |
tree | 4db0c2cc5de6b4fe5d01fb5cc762b6a74ce32d34 /src/libdatastruct/genset_iter.c | |
parent | 157ecd01d6cc4598ce4b0ec9bd477abbbf41d6c5 (diff) | |
download | skalibs-b59ce39f9779cf4b1ad423783b6a532f94a8e880.tar.xz |
Add cancellation to iterators over avltree(n) and genset(dyn)
Diffstat (limited to 'src/libdatastruct/genset_iter.c')
-rw-r--r-- | src/libdatastruct/genset_iter.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libdatastruct/genset_iter.c b/src/libdatastruct/genset_iter.c index fba95de..f78945d 100644 --- a/src/libdatastruct/genset_iter.c +++ b/src/libdatastruct/genset_iter.c @@ -4,16 +4,16 @@ #include <skalibs/functypes.h> #include <skalibs/genset.h> -unsigned int genset_iter (genset *g, iterfunc_t_ref f, void *stuff) +unsigned int genset_iter_nocancel (genset *g, unsigned int n, 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)) + unsigned char bits[bitarray_div8(n)] ; + unsigned int i = 0, j = 0, m = genset_n(g) ; + bitarray_setn(bits, 0, n) ; + for (; i < g->sp ; i++) if (g->freelist[i] < n) bitarray_clear(bits, g->freelist[i]) ; + for (i = 0 ; (i < n) && (j < m) ; i++) if (bitarray_peek(bits, i)) { j++ ; - if ((*f)(g->storage + i * g->esize, stuff)) n++ ; + if (!(*f)(g->storage + i * g->esize, stuff)) break ; } - return n ; + return i ; } |