skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 2b0ab2120becaa40b777e7c43bfa57cb0397e3a9
parent 60ab25645e64e5e054d9b101091e3b1abd87d36e
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Tue,  5 Jan 2016 20:04:57 +0000

 Add bitarray_first{clear,set}_skip (thx jjk)
 version: rc for 2.3.9.0 after Makefile fix

Diffstat:
Mdoc/index.html | 2+-
Mdoc/libstddjb/bitarray.html | 14++++++++++++++
Mdoc/upgrade.html | 7+++++++
Mpackage/deps.mak | 2++
Mpackage/info | 2+-
Msrc/include/skalibs/bitarray.h | 5+++++
Asrc/libstddjb/bitarray_firstclear_skip.c | 15+++++++++++++++
Asrc/libstddjb/bitarray_firstset_skip.c | 15+++++++++++++++
8 files changed, 60 insertions(+), 2 deletions(-)

diff --git 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 @@ -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> &gt; <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> &gt; <em>len</em>. +</p> + </body> </html> diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) ; +}