skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

genset_iter_nocancel.c (548B)


      1 /* ISC license. */
      2 
      3 #include <stdint.h>
      4 
      5 #include <skalibs/bitarray.h>
      6 #include <skalibs/genset.h>
      7 
      8 uint32_t genset_iter_nocancel (genset *g, uint32_t n, iter_func_ref f, void *stuff)
      9 {
     10   unsigned char bits[bitarray_div8(n)] ;
     11   uint32_t i = 0, j = 0, m = genset_n(g) ;
     12   bitarray_setn(bits, 0, n) ;
     13   for (; i < g->sp ; i++) if (g->freelist[i] < n) bitarray_clear(bits, g->freelist[i]) ;
     14   for (i = 0 ; (i < n) && (j < m) ; i++) if (bitarray_peek(bits, i))
     15   {
     16     j++ ;
     17     if (!(*f)(g->storage + i * g->esize, stuff)) break ;
     18   }
     19   return i ;
     20 }