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

#include <sys/types.h>
#include <skalibs/bitarray.h>

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