Fix tabbing
[satune.git] / src / Collections / corestructs.h
1 #ifndef CORESTRUCTS_H
2 #define CORESTRUCTS_H
3
4 #include "cppvector.h"
5 #include "hashset.h"
6
7 //How much should we shift pointers when computing hash functions
8 //5 appears to be the minimum value for Ubuntu 64-bit
9
10 #define PTRSHIFT 5
11
12 class BooleanEdge {
13 public:
14         BooleanEdge() : b(NULL) {}
15         BooleanEdge(Boolean *_b) : b(_b) {}
16         BooleanEdge negate() {return BooleanEdge((Boolean *)(((uintptr_t) b) ^ 1));}
17         bool operator==(BooleanEdge e) { return b == e.b;}
18         bool operator!=(BooleanEdge e) { return b != e.b;}
19         bool isNegated() { return ((uintptr_t) b) & 1; }
20         Boolean *getBoolean() {return (Boolean *)(((uintptr_t)b) & ~((uintptr_t) 1));}
21         Boolean *getRaw() {return b;}
22         Boolean *operator->() {return getBoolean();}
23         operator bool() const {return b != NULL;}
24 private:
25         Boolean *b;
26 };
27
28 inline bool boolEdgeEquals(BooleanEdge b1, BooleanEdge b2) {
29         return b1 == b2;
30 }
31
32 inline unsigned int boolEdgeHash(BooleanEdge b) {
33         return (unsigned int) (((uintptr_t)b.getRaw()) >> PTRSHIFT);
34 }
35
36 typedef Hashset<BooleanEdge, uintptr_t, PTRSHIFT, &boolEdgeHash, &boolEdgeEquals> HashsetBooleanEdge;
37 typedef Hashset<Order *, uintptr_t, PTRSHIFT> HashsetOrder;
38 typedef SetIterator<BooleanEdge, uintptr_t, PTRSHIFT, &boolEdgeHash, &boolEdgeEquals> SetIteratorBooleanEdge;
39 typedef SetIterator<Order *, uintptr_t, PTRSHIFT> SetIteratorOrder;
40
41 #endif