diff options
Diffstat (limited to 'src/zbset.c')
| -rw-r--r-- | src/zbset.c | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/zbset.c b/src/zbset.c index 2874238..cc7b2b0 100644 --- a/src/zbset.c +++ b/src/zbset.c @@ -2,38 +2,45 @@ #include "internals.h" -void -zbset(z_t a, z_t b, size_t bit, int action) -{ - zahl_char_t mask = 1; - size_t chars; - - chars = FLOOR_BITS_TO_CHARS(bit); - bit = BITS_IN_LAST_CHAR(bit); - mask <<= bit; +#define PROLOGUE(MAY_INCREASE)\ + zahl_char_t mask = 1;\ + size_t chars = FLOOR_BITS_TO_CHARS(bit);\ + if (MAY_INCREASE) {\ + if (zzero(a)) {\ + a->used = 0;\ + SET_SIGNUM(a, 1);\ + }\ + if (unlikely(chars >= a->used)) {\ + ENSURE_SIZE(a, chars + 1);\ + zmemset(a->chars + a->used, 0, chars + 1 - a->used);\ + a->used = chars + 1;\ + }\ + } else if (unlikely(chars >= a->used)) {\ + return;\ + }\ + bit = BITS_IN_LAST_CHAR(bit);\ + mask <<= bit - SET(a, b); - if (action) { - if (zzero(a)) { - a->used = 0; - SET_SIGNUM(a, 1); - } - if (a->used <= chars) { - ENSURE_SIZE(a, chars + 1); - zmemset(a->chars + a->used, 0, chars + 1 - a->used); - a->used = chars + 1; - } - } +void +zbset_impl_set(z_t a, z_t b, size_t bit) +{ + PROLOGUE(1); + a->chars[chars] |= mask; +} - if (action > 0) { - a->chars[chars] |= mask; - return; - } else if (action < 0) { - a->chars[chars] ^= mask; - } else if (chars < a->used) { - a->chars[chars] &= ~mask; - } +void +zbset_impl_clear(z_t a, z_t b, size_t bit) +{ + PROLOGUE(0); + a->chars[chars] &= ~mask; + TRIM_AND_ZERO(a); +} +void +zbset_impl_flip(z_t a, z_t b, size_t bit) +{ + PROLOGUE(1); + a->chars[chars] ^= mask; TRIM_AND_ZERO(a); } |
