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

#include <skalibs/bitarray.h>

unsigned int bitarray_firstset_skip (register unsigned char const *s, unsigned int max, unsigned int skip)
{
  register unsigned int i = bitarray_div8(skip) ;
  register unsigned int 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) ;
}