bitarray_clearsetn.c (654B)
1 /* ISC license. */ 2 3 #include <skalibs/bitarray.h> 4 5 void bitarray_clearsetn (unsigned char *s, size_t a, size_t b, int h) 6 { 7 if (!b) return ; 8 b += a ; 9 if ((a >> 3) == ((b-1) >> 3)) 10 { 11 unsigned char mask = (1 << (a & 7)) - 1 ^ (1 << (1 + (b-1 & 7))) - 1 ; 12 if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; 13 } 14 else 15 { 16 unsigned char mask = ~((1 << (a & 7)) - 1) ; 17 size_t i = (a>>3) + 1 ; 18 if (h) s[a>>3] |= mask ; else s[a>>3] &= ~mask ; 19 mask = h ? 0xff : 0x00 ; 20 for (; i < b>>3 ; i++) s[i] = mask ; 21 if (b & 7) 22 { 23 mask = (1 << (b & 7)) - 1 ; 24 if (h) s[b>>3] |= mask ; else s[b>>3] &= ~mask ; 25 } 26 } 27 }