commit 3e104e532b49038f94ec9770bbe3e765472cf613
parent beda73643f21cc768f4f56e8ee205b704a019d6a
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Thu, 25 Feb 2016 15:02:38 -0500
a little code compaction
Diffstat:
| M | lisc/util.c | | | 38 | +++++++++++++++----------------------- |
1 file changed, 15 insertions(+), 23 deletions(-)
diff --git a/lisc/util.c b/lisc/util.c
@@ -248,15 +248,6 @@ bsinit(BSet *bs, uint n)
bs->chunk = alloc(n * sizeof bs->chunk[0]);
}
-void
-bszero(BSet *bs)
-{
- uint n;
-
- for (n=0; n<bs->nchunk; n++)
- bs->chunk[n] = 0;
-}
-
uint
bscount(BSet *bs)
{
@@ -297,24 +288,25 @@ bsclr(BSet *bs, uint elt)
bs->chunk[elt/NBit] &= ~BIT(elt%NBit);
}
-void
-bsunion(BSet *a, BSet *b)
-{
- uint i;
+#define BSOP(f, op) \
+ void \
+ f(BSet *a, BSet *b) \
+ { \
+ uint i; \
+ \
+ assert(a->nchunk == b->nchunk); \
+ for (i=0; i<a->nchunk; i++) \
+ a->chunk[i] op b->chunk[i]; \
+ }
- assert(a->nchunk == b->nchunk);
- for (i=0; i<a->nchunk; i++)
- a->chunk[i] |= b->chunk[i];
-}
+BSOP(bsunion, |=)
+BSOP(bsinter, &=)
+BSOP(bsdiff, &= ~)
void
-bsinter(BSet *a, BSet *b)
+bszero(BSet *bs)
{
- uint i;
-
- assert(a->nchunk == b->nchunk);
- for (i=0; i<a->nchunk; i++)
- a->chunk[i] &= b->chunk[i];
+ bsdiff(bs, bs);
}
/* Iterates on a bitset, use as follows.