From 3e104e532b49038f94ec9770bbe3e765472cf613 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 25 Feb 2016 15:02:38 -0500 Subject: a little code compaction --- lisc/util.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'lisc') diff --git a/lisc/util.c b/lisc/util.c index f6281f8..bfddbff 100644 --- 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; nnchunk; 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; inchunk; i++) \ + a->chunk[i] op b->chunk[i]; \ + } - assert(a->nchunk == b->nchunk); - for (i=0; inchunk; 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; inchunk; i++) - a->chunk[i] &= b->chunk[i]; + bsdiff(bs, bs); } /* Iterates on a bitset, use as follows. -- cgit 1.4.1