1 #ifndef __UIUC_CS_CHARM_CKBITVECTOR_H
2 #define __UIUC_CS_CHARM_CKBITVECTOR_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
;
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()));
31 return (((prio_t
)0x1)<<shift
);
35 static prio_t
ilog2(prio_t val
) {
38 while ( val
> (1u<<log
) ) { log
++; }
47 int Length() const { return (int)usedBits
; }
51 CkBitVector(const CkBitVector
&b
);
52 CkBitVector(prio_t bits
);
53 CkBitVector(prio_t value
, prio_t choices
);
57 CkBitVector
& operator=(const CkBitVector
&b
);
59 // Bit operations. 0 is the least significant bit, and 32 (+) is the
60 // most significant bit.
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
);
99 // For debugging in megatest
101 CmiUInt4
* getData() { return data
; }
102 unsigned int getDataLength() { return chunks(usedBits
); }
105 friend class CkEntryOptions
;
108 PUPmarshall(CkBitVector
)
110 #endif /* __UIUC_CS_CHARM_CKBITVECTOR_H */