summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-02-24 11:28:18 -0800
committerOri Bernstein <ori@eigenstate.org>2016-02-24 11:28:18 -0800
commit16461118be707834c1b2b43774a350fe6f6cc45c (patch)
tree575369028889f614fbffa6e139f9b1758bbad567
parent0b5023c54b5310de851219ebbcd5f27876a005fb (diff)
downloadmc-16461118be707834c1b2b43774a350fe6f6cc45c.tar.gz
Move bitset.c to util dir.
-rw-r--r--parse/Makefile1
-rw-r--r--parse/parse.h26
-rw-r--r--util/Makefile1
-rw-r--r--util/bitset.c (renamed from parse/bitset.c)1
-rw-r--r--util/util.h30
5 files changed, 31 insertions, 28 deletions
diff --git a/parse/Makefile b/parse/Makefile
index 4df4b0c..fd24e92 100644
--- a/parse/Makefile
+++ b/parse/Makefile
@@ -1,6 +1,5 @@
LIB=libparse.a
OBJ=\
- bitset.o \
dump.o \
err.o \
fold.o \
diff --git a/parse/parse.h b/parse/parse.h
index 73db308..80b3be6 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -365,32 +365,6 @@ extern char *nodestr[];
extern char *litstr[];
extern char *tidstr[];
-/* data structures */
-Bitset *mkbs(void);
-void bsfree(Bitset *bs);
-Bitset *bsdup(Bitset *bs);
-Bitset *bsclear(Bitset *bs);
-void delbs(Bitset *bs);
-void bsput(Bitset *bs, size_t elt);
-void bsdel(Bitset *bs, size_t elt);
-void bsunion(Bitset *a, Bitset *b);
-void bsintersect(Bitset *a, Bitset *b);
-void bsdiff(Bitset *a, Bitset *b);
-int bseq(Bitset *a, Bitset *b);
-int bsissubset(Bitset *set, Bitset *sub);
-int bsisempty(Bitset *set);
-int bsiter(Bitset *bs, size_t *elt);
-size_t bsmax(Bitset *bs);
-size_t bscount(Bitset *bs);
-/* inline for speed */
-static inline int bshas(Bitset *bs, size_t elt)
-{
- if (elt >= bs->nchunks * 8 * sizeof(size_t))
- return 0;
- return (bs->chunks[elt / (8 * sizeof(size_t))] & (1ULL << (elt % (8 * sizeof(size_t))))) !=
- 0;
-}
-
/* useful key types */
int liteq(Node *a, Node *b);
int litvaleq(Node *a, Node *b);
diff --git a/util/Makefile b/util/Makefile
index d314cd8..410caf0 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -1,6 +1,7 @@
LIB=libutil.a
OBJ= \
alloc.o \
+ bitset.o \
htab.o \
pack.o \
util.o \
diff --git a/parse/bitset.c b/util/bitset.c
index ea3c398..6e85c33 100644
--- a/parse/bitset.c
+++ b/util/bitset.c
@@ -7,7 +7,6 @@
#include <string.h>
#include "util.h"
-#include "parse.h"
#define Sizetbits (CHAR_BIT * sizeof(size_t)) /* used in graph reprs */
diff --git a/util/util.h b/util/util.h
index 2e28d1e..829340d 100644
--- a/util/util.h
+++ b/util/util.h
@@ -66,6 +66,36 @@ char *sbfin(Strbuf *sb);
void sbputs(Strbuf *sb, char *s);
void sbputb(Strbuf *sb, char b);
+/* bit sets */
+Bitset *mkbs(void);
+void bsfree(Bitset *bs);
+Bitset *bsdup(Bitset *bs);
+Bitset *bsclear(Bitset *bs);
+void delbs(Bitset *bs);
+void bsput(Bitset *bs, size_t elt);
+void bsdel(Bitset *bs, size_t elt);
+void bsunion(Bitset *a, Bitset *b);
+void bsintersect(Bitset *a, Bitset *b);
+void bsdiff(Bitset *a, Bitset *b);
+int bseq(Bitset *a, Bitset *b);
+int bsissubset(Bitset *set, Bitset *sub);
+int bsisempty(Bitset *set);
+int bsiter(Bitset *bs, size_t *elt);
+size_t bsmax(Bitset *bs);
+size_t bscount(Bitset *bs);
+/* inline for speed */
+static inline int bshas(Bitset *bs, size_t elt)
+{
+ size_t eltidx, eltshift;
+
+ if (elt >= bs->nchunks * 8 * sizeof(size_t))
+ return 0;
+ eltidx = elt / (8 * sizeof(size_t));
+ eltshift = elt % (8 * sizeof(size_t));
+ return (bs->chunks[eltidx] & (1ULL << (elt % (8 * sizeof(size_t))))) != 0;
+}
+
+
/* hash tables */
Htab *mkht(ulong (*hash)(void *key), int (*cmp)(void *k1, void *k2));
void htfree(Htab *ht);