diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-01-05 20:04:57 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-01-05 20:04:57 +0000 |
commit | 2b0ab2120becaa40b777e7c43bfa57cb0397e3a9 (patch) | |
tree | f20e09817ee647b750fb0e59d8cc543301b29a3e | |
parent | 60ab25645e64e5e054d9b101091e3b1abd87d36e (diff) | |
download | skalibs-2b0ab2120becaa40b777e7c43bfa57cb0397e3a9.tar.xz |
Add bitarray_first{clear,set}_skip (thx jjk)
version: rc for 2.3.9.0 after Makefile fix
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/libstddjb/bitarray.html | 14 | ||||
-rw-r--r-- | doc/upgrade.html | 7 | ||||
-rw-r--r-- | package/deps.mak | 2 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/include/skalibs/bitarray.h | 5 | ||||
-rw-r--r-- | src/libstddjb/bitarray_firstclear_skip.c | 15 | ||||
-rw-r--r-- | src/libstddjb/bitarray_firstset_skip.c | 15 |
8 files changed, 60 insertions, 2 deletions
diff --git a/doc/index.html b/doc/index.html index d310551..3606019 100644 --- a/doc/index.html +++ b/doc/index.html @@ -60,7 +60,7 @@ with a standard C development environment </li> <h3> Download </h3> <ul> - <li> The current released version of skalibs is <a href="skalibs-2.3.8.3.tar.gz">2.3.8.3</a>. </li> + <li> The current released version of skalibs is <a href="skalibs-2.3.9.0.tar.gz">2.3.9.0</a>. </li> <li> Alternatively, you can checkout a copy of the skalibs git repository: <pre> git clone git://git.skarnet.org/skalibs </pre> </li> </ul> diff --git a/doc/libstddjb/bitarray.html b/doc/libstddjb/bitarray.html index 03f81df..0695ff1 100644 --- a/doc/libstddjb/bitarray.html +++ b/doc/libstddjb/bitarray.html @@ -123,10 +123,24 @@ the total number of bits. If all bits in <em>s</em> are set, <em>len</em> is ret </p> <p> +<code> unsigned int bitarray_firstclear_skip (unsigned char const *s, unsigned int len, unsigned int skip) </code> <br /> +Like <tt>bitarray_firstclear</tt>, but the first <em>skip</em> bits are +ignored: the function cannot return less than <em>skip</em>. It is a +programming error if <em>skip</em> > <em>len</em>. +</p> + +<p> <code> unsigned int bitarray_firstset (unsigned char const *s, unsigned int len) </code> <br /> Returns the number of the first set bit in <em>s</em>, <em>len</em> being the total number of bits. If all bits in <em>s</em> are clear, <em>len</em> is returned. </p> +<p> +<code> unsigned int bitarray_firstset_skip (unsigned char const *s, unsigned int len, unsigned int skip) </code> <br /> +Like <tt>bitarray_firstset</tt>, but the first <em>skip</em> bits are +ignored: the function cannot return less than <em>skip</em>. It is a +programming error if <em>skip</em> > <em>len</em>. +</p> + </body> </html> diff --git a/doc/upgrade.html b/doc/upgrade.html index 53b65a1..d67960f 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -18,6 +18,13 @@ <h1> What has changed in skalibs </h1> +<h2> in 2.3.9.0 </h2> + +<ul> + <li> New functions: <tt>bitarray_firstclear_skip</tt> and +<tt>bitarray_firstset_skip</tt>. </li> +</ul> + <h2> in 2.3.8.3 </h2> <ul> diff --git a/package/deps.mak b/package/deps.mak index 7a4b6d9..afa6823 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -211,7 +211,9 @@ src/libstddjb/bitarray_and.o src/libstddjb/bitarray_and.lo: src/libstddjb/bitarr src/libstddjb/bitarray_clearsetn.o src/libstddjb/bitarray_clearsetn.lo: src/libstddjb/bitarray_clearsetn.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_count.o src/libstddjb/bitarray_count.lo: src/libstddjb/bitarray_count.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstclear.o src/libstddjb/bitarray_firstclear.lo: src/libstddjb/bitarray_firstclear.c src/include/skalibs/bitarray.h +src/libstddjb/bitarray_firstclear_skip.o src/libstddjb/bitarray_firstclear_skip.lo: src/libstddjb/bitarray_firstclear_skip.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_firstset.o src/libstddjb/bitarray_firstset.lo: src/libstddjb/bitarray_firstset.c src/include/skalibs/bitarray.h +src/libstddjb/bitarray_firstset_skip.o src/libstddjb/bitarray_firstset_skip.lo: src/libstddjb/bitarray_firstset_skip.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_not.o src/libstddjb/bitarray_not.lo: src/libstddjb/bitarray_not.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_or.o src/libstddjb/bitarray_or.lo: src/libstddjb/bitarray_or.c src/include/skalibs/bitarray.h src/libstddjb/bitarray_testandpoke.o src/libstddjb/bitarray_testandpoke.lo: src/libstddjb/bitarray_testandpoke.c src/include/skalibs/bitarray.h diff --git a/package/info b/package/info index 8404b6a..ef65fdc 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=skalibs -version=2.3.8.3 +version=2.3.9.0 category=prog package_macro_name=SKALIBS 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) ; +} |