summaryrefslogtreecommitdiff
path: root/src/libstddjb/bitarray_firstclear_skip.c
blob: 5d8eb7bf152eaffe5fcdf809d8bc027421506846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* ISC license. */

#include <skalibs/bitarray.h>

size_t bitarray_firstclear_skip (unsigned char const *s, size_t max, size_t skip)
{
  size_t i = bitarray_div8(skip) ;
  size_t j = i << 3 > max ? max : i << 3 ;
  if (i && s[i-1] != 0xffU)
  {
    while ((skip < j) && bitarray_peek(s, skip)) skip++ ;
    if (skip < j) return skip ;
  }
  return j + bitarray_firstclear(s + i, max - j) ;
}