summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-02-25 15:02:38 -0500
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-02-25 15:05:40 -0500
commit3e104e532b49038f94ec9770bbe3e765472cf613 (patch)
tree76e62629a4f180c3749aebf2964517fd869fa887 /lisc
parentbeda73643f21cc768f4f56e8ee205b704a019d6a (diff)
downloadroux-3e104e532b49038f94ec9770bbe3e765472cf613.tar.gz
a little code compaction
Diffstat (limited to 'lisc')
-rw-r--r--lisc/util.c38
1 files changed, 15 insertions, 23 deletions
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; 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.