summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-01-05 20:04:57 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-01-05 20:04:57 +0000
commit2b0ab2120becaa40b777e7c43bfa57cb0397e3a9 (patch)
treef20e09817ee647b750fb0e59d8cc543301b29a3e /src
parent60ab25645e64e5e054d9b101091e3b1abd87d36e (diff)
downloadskalibs-2b0ab2120becaa40b777e7c43bfa57cb0397e3a9.tar.xz
Add bitarray_first{clear,set}_skip (thx jjk)
version: rc for 2.3.9.0 after Makefile fix
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/bitarray.h5
-rw-r--r--src/libstddjb/bitarray_firstclear_skip.c15
-rw-r--r--src/libstddjb/bitarray_firstset_skip.c15
3 files changed, 35 insertions, 0 deletions
diff --git a/src/include/skalibs/bitarray.h b/src/include/skalibs/bitarray.h
index ed44fed..fc9b16d 100644
--- a/src/include/skalibs/bitarray.h
+++ b/src/include/skalibs/bitarray.h
@@ -24,6 +24,11 @@ extern int bitarray_testandpoke (unsigned char *, unsigned int, int) ;
extern unsigned int bitarray_firstclear (unsigned char const *, unsigned int) gccattr_pure ;
extern unsigned int bitarray_firstset (unsigned char const *, unsigned int) gccattr_pure ;
#define bitarray_first(s, n, h) ((h) ? bitarray_firstset(s, n) : bitarray_firstclear(s, n))
+
+extern unsigned int bitarray_firstclear_skip (unsigned char const *, unsigned int, unsigned int) gccattr_pure ;
+extern unsigned int bitarray_firstset_skip (unsigned char const *, unsigned int, unsigned int) gccattr_pure ;
+#define bitarray_first_skip(s, n, k, h) ((h) ? bitarray_firstset_skip(s, n, k) : bitarray_firstclear_skip(s, n, k))
+
extern unsigned int bitarray_countones (unsigned char const *, unsigned int) gccattr_pure ;
extern void bitarray_not (unsigned char *, unsigned int, unsigned int) ;
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) ;
+}