diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libstddjb/bitarray_clearsetn.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libstddjb/bitarray_clearsetn.c')
-rw-r--r-- | src/libstddjb/bitarray_clearsetn.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libstddjb/bitarray_clearsetn.c b/src/libstddjb/bitarray_clearsetn.c new file mode 100644 index 0000000..b3f46f1 --- /dev/null +++ b/src/libstddjb/bitarray_clearsetn.c @@ -0,0 +1,24 @@ +/* ISC license. */ + +#include <skalibs/bitarray.h> + +void bitarray_clearsetn (register unsigned char *s, register unsigned int a, register unsigned int b, register int h) +{ + if (!b) return ; + b += a ; + if ((a >> 3) == ((b-1) >> 3)) + { + register unsigned char mask = ((1 << (a & 7)) - 1) ^ ((1 << (b & 7)) - 1) ; + if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; + } + else + { + register unsigned char mask = ~((1 << (a & 7)) - 1) ; + register unsigned int i = (a>>3) + 1 ; + if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; + mask = h ? 0xff : 0x00 ; + for (; i < b>>3 ; i++) s[i] = mask ; + mask = (1 << (b & 7)) - 1 ; + if (h) s[b>>3] |= mask ; else s[b>>3] &= ~mask ; + } +} |