diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/gensetdyn.h | 2 | ||||
-rw-r--r-- | src/libdatastruct/gensetdyn_iter.c | 12 | ||||
-rw-r--r-- | src/libdatastruct/gensetdyn_iter_withcancel.c | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/include/skalibs/gensetdyn.h b/src/include/skalibs/gensetdyn.h index 7cb8f1a..5171a00 100644 --- a/src/include/skalibs/gensetdyn.h +++ b/src/include/skalibs/gensetdyn.h @@ -36,7 +36,7 @@ extern int gensetdyn_delete (gensetdyn *, unsigned int) ; #define GENSETDYN_P(type, g, i) ((type *)gensetdyn_p(g, i)) extern unsigned int gensetdyn_iter_nocancel (gensetdyn *, unsigned int, iterfunc_t_ref, void *) ; -#define gensetdyn_iter(g, f, stuff) (gensetdyn_iter_nocancel(g, (g)->storage.len, f, stuff) == (g)->storage.len) +#define gensetdyn_iter(g, f, stuff) gensetdyn_iter_nocancel(g, gensetdyn_n(g), f, stuff) extern int gensetdyn_iter_withcancel (gensetdyn *, iterfunc_t_ref, iterfunc_t_ref, void *) ; #endif diff --git a/src/libdatastruct/gensetdyn_iter.c b/src/libdatastruct/gensetdyn_iter.c index 586aa11..b4e1638 100644 --- a/src/libdatastruct/gensetdyn_iter.c +++ b/src/libdatastruct/gensetdyn_iter.c @@ -10,17 +10,17 @@ unsigned int gensetdyn_iter_nocancel (gensetdyn *g, unsigned int n, iterfunc_t_r 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(n)] ; - unsigned int i = 0, j = 0, m = gensetdyn_n(g) ; + unsigned char bits[bitarray_div8(g->storage.len)] ; + unsigned int i = 0, j = 0 ; register unsigned int *fl = genalloc_s(unsigned int, &g->freelist) ; register unsigned int sp = genalloc_len(unsigned int, &g->freelist) ; - bitarray_setn(bits, 0, n) ; + bitarray_setn(bits, 0, g->storage.len) ; - 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)) + for (; i < sp ; i++) if (fl[i] < g->storage.len) bitarray_clear(bits, fl[i]) ; + for (i = 0 ; (i < g->storage.len) && (j < n) ; i++) if (bitarray_peek(bits, i)) { j++ ; if (!(*f)(gensetdyn_p(g, i), stuff)) break ; } - return i ; + return j ; } diff --git a/src/libdatastruct/gensetdyn_iter_withcancel.c b/src/libdatastruct/gensetdyn_iter_withcancel.c index c524b1c..8dc2a18 100644 --- a/src/libdatastruct/gensetdyn_iter_withcancel.c +++ b/src/libdatastruct/gensetdyn_iter_withcancel.c @@ -6,8 +6,8 @@ int gensetdyn_iter_withcancel (gensetdyn *g, iterfunc_t_ref f, iterfunc_t_ref cancelf, void *stuff) { - unsigned int n = gensetdyn_iter_nocancel(g, g->storage.len, f, stuff) ; - if (n < g->storage.len) + unsigned int n = gensetdyn_iter_nocancel(g, gensetdyn_n(g), f, stuff) ; + if (n < gensetdyn_n(g)) { int e = errno ; gensetdyn_iter_nocancel(g, n, cancelf, stuff) ; |