skalibs

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

bitarray_firstset_skip.c (380B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/bitarray.h>
      4 
      5 size_t bitarray_firstset_skip (unsigned char const *s, size_t max, size_t skip)
      6 {
      7   size_t i = bitarray_div8(skip) ;
      8   size_t j = i << 3 > max ? max : i << 3 ;
      9   if (i && s[i-1])
     10   {
     11     while ((skip < j) && !bitarray_peek(s, skip)) skip++ ;
     12     if (skip < j) return skip ;
     13   }
     14   return j + bitarray_firstset(s + i, max - j) ;
     15 }