a new build option --enable-tracing-commthread
[charm.git] / src / util / ckbitvector.h
blobdffc25038c76eaef7a02ce87a1d333769c507e84
1 #ifndef __UIUC_CS_CHARM_CKBITVECTOR_H
2 #define __UIUC_CS_CHARM_CKBITVECTOR_H
4 #include "ckstream.h"
6 /* ************************************************************************
8 * 0 indicates the least important bit of the bitvector
9 * n indicates the most inportant bit of the bitvector
11 * the n'th bit sits at the highest bit of the first integer.
12 * the 0'th bit sits at the lowest bit of the last integer.
14 * ************************************************************************ */
16 typedef CmiUInt4 prio_t;
18 class CkBitVector {
19 protected:
20 prio_t usedBits;
21 prio_t *data;
23 protected:
24 static prio_t chunkBits() { return chunkSize()*8; }
25 static prio_t chunkSize() { return sizeof(prio_t); }
26 static prio_t chunks(prio_t n) { return (n + chunkBits()-1) / chunkBits(); }
27 prio_t offset(prio_t bit) const { return chunks(usedBits-bit)-1; }
28 prio_t mask(prio_t bit) const {
29 unsigned int shift = (chunkBits()-(usedBits%chunkBits())+(bit%chunkBits()));
30 shift %= chunkBits();
31 return (((prio_t)0x1)<<shift);
34 public:
35 static prio_t ilog2(prio_t val) {
36 prio_t log = 0u;
37 if ( val != 0u ) {
38 while ( val > (1u<<log) ) { log++; }
40 return log;
43 protected:
44 void wipeData();
46 public:
47 int Length() const { return (int)usedBits; }
49 public:
50 CkBitVector();
51 CkBitVector(const CkBitVector &b);
52 CkBitVector(prio_t bits);
53 CkBitVector(prio_t value, prio_t choices);
55 ~CkBitVector();
57 CkBitVector & operator=(const CkBitVector &b);
59 // Bit operations. 0 is the least significant bit, and 32 (+) is the
60 // most significant bit.
61 CkBitVector & Zero();
62 CkBitVector & Invert();
63 CkBitVector & Clear(prio_t bit);
64 CkBitVector & Set(prio_t bit);
65 CmiBool Test(prio_t bit) const;
67 // Shift down and shift up shift the bits in the bit vector by bit
68 // bits around. The bits in the vector are moved up or down the
69 // specified amount. The size of the bit vector does not change
70 CkBitVector & ShiftDown(prio_t bits);
71 CkBitVector & ShiftUp(prio_t bits);
73 // Change the size of the bit vector
74 CkBitVector & Resize(prio_t bits);
76 // Union, Intersection, Difference
77 CkBitVector & Union(CkBitVector const &b);
78 CkBitVector & Intersection(CkBitVector const &b);
79 CkBitVector & Difference(CkBitVector const &b);
81 // Concatenate two bit vectors together
82 CkBitVector & Concat(CkBitVector const &b);
84 // Comparison operators
85 CmiBool operator==(const CkBitVector &b) const { return CmiFalse; } // HERE
86 CmiBool operator!=(const CkBitVector &b) const { return (CmiBool)!(*this==b); }
87 CmiBool operator<(const CkBitVector &b) const { return CmiFalse; } // HERE
88 CmiBool operator<=(const CkBitVector &b) const { return (CmiBool)(*this==b||*this>b); }
89 CmiBool operator>(const CkBitVector &b) const { return CmiFalse; } // HERE
90 CmiBool operator>=(const CkBitVector &b) const { return (CmiBool)(*this==b||*this<b); }
92 // Print the bit vector to either output stream type
93 friend CkOutStream & operator<< (CkOutStream &ckos, CkBitVector const b);
94 friend CkErrStream & operator<< (CkErrStream &ckes, CkBitVector const b);
96 // And for charm
97 void pup(PUP::er &p);
99 // For debugging in megatest
100 #ifdef DEBUGGING
101 CmiUInt4 * getData() { return data; }
102 unsigned int getDataLength() { return chunks(usedBits); }
103 #endif
105 friend class CkEntryOptions;
108 PUPmarshall(CkBitVector)
110 #endif /* __UIUC_CS_CHARM_CKBITVECTOR_H */