summaryrefslogtreecommitdiff
path: root/src/libdatastruct/gensetdyn_iter.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-09 16:10:40 +0000
commitb59ce39f9779cf4b1ad423783b6a532f94a8e880 (patch)
tree4db0c2cc5de6b4fe5d01fb5cc762b6a74ce32d34 /src/libdatastruct/gensetdyn_iter.c
parent157ecd01d6cc4598ce4b0ec9bd477abbbf41d6c5 (diff)
downloadskalibs-b59ce39f9779cf4b1ad423783b6a532f94a8e880.tar.xz
Add cancellation to iterators over avltree(n) and genset(dyn)
Diffstat (limited to 'src/libdatastruct/gensetdyn_iter.c')
-rw-r--r--src/libdatastruct/gensetdyn_iter.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libdatastruct/gensetdyn_iter.c b/src/libdatastruct/gensetdyn_iter.c
index 51d598b..586aa11 100644
--- a/src/libdatastruct/gensetdyn_iter.c
+++ b/src/libdatastruct/gensetdyn_iter.c
@@ -4,23 +4,23 @@
#include <skalibs/functypes.h>
#include <skalibs/gensetdyn.h>
-unsigned int gensetdyn_iter (gensetdyn *g, iterfunc_t_ref f, void *stuff)
+unsigned int gensetdyn_iter_nocancel (gensetdyn *g, unsigned int n, iterfunc_t_ref f, void *stuff)
{
/*
XXX: we may be called by a freeing function, so we cannot alloc -
XXX: so pray that the bitarray fits in the stack.
*/
- unsigned char bits[bitarray_div8(g->storage.len)] ;
- unsigned int i = 0, j = 0, n = 0, m = gensetdyn_n(g) ;
+ unsigned char bits[bitarray_div8(n)] ;
+ unsigned int i = 0, j = 0, m = gensetdyn_n(g) ;
register unsigned int *fl = genalloc_s(unsigned int, &g->freelist) ;
register unsigned int sp = genalloc_len(unsigned int, &g->freelist) ;
- bitarray_setn(bits, 0, g->storage.len) ;
+ bitarray_setn(bits, 0, n) ;
- for (; i < sp ; i++) bitarray_clear(bits, fl[i]) ;
- for (i = 0 ; (i < g->storage.len) && (j < m) ; i++) if (bitarray_peek(bits, i))
+ for (; i < sp ; i++) if (fl[i] < n) bitarray_clear(bits, fl[i]) ;
+ for (i = 0 ; (i < n) && (j < m) ; i++) if (bitarray_peek(bits, i))
{
j++ ;
- if ((*f)(gensetdyn_p(g, i), stuff)) n++ ;
+ if (!(*f)(gensetdyn_p(g, i), stuff)) break ;
}
- return n ;
+ return i ;
}