skalibs

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

bitarray_firstset.c (310B)


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