summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/bitarray_firstclear_skip.c15
-rw-r--r--src/libstddjb/bitarray_firstset_skip.c15
2 files changed, 30 insertions, 0 deletions
diff --git a/src/libstddjb/bitarray_firstclear_skip.c b/src/libstddjb/bitarray_firstclear_skip.c
new file mode 100644
index 0000000..8a32dba
--- /dev/null
+++ b/src/libstddjb/bitarray_firstclear_skip.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include <skalibs/bitarray.h>
+
+unsigned int bitarray_firstclear_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] != 0xffU)
+ {
+ while ((skip < j) && bitarray_peek(s, skip)) skip++ ;
+ if (skip < j) return skip ;
+ }
+ return j + bitarray_firstclear(s + i, max - j) ;
+}
diff --git a/src/libstddjb/bitarray_firstset_skip.c b/src/libstddjb/bitarray_firstset_skip.c
new file mode 100644
index 0000000..2f269cf
--- /dev/null
+++ b/src/libstddjb/bitarray_firstset_skip.c
@@ -0,0 +1,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) ;
+}