reference& operator=(bool t) {
if (t)
- *WordRef |= 1L << BitPos;
+ *WordRef |= BitWord(1) << BitPos;
else
- *WordRef &= ~(1L << BitPos);
+ *WordRef &= ~(BitWord(1) << BitPos);
return *this;
}
operator bool() const {
- return ((*WordRef) & (1L << BitPos)) ? true : false;
+ return ((*WordRef) & (BitWord(1) << BitPos)) ? true : false;
}
};
/// BitVector default ctor - Creates an empty bitvector.
BitVector() : Size(0), Capacity(0) {
- Bits = 0;
+ Bits = nullptr;
}
/// BitVector ctor - Creates a bitvector of specified number of bits. All
/// BitVector copy ctor.
BitVector(const BitVector &RHS) : Size(RHS.size()) {
if (Size == 0) {
- Bits = 0;
+ Bits = nullptr;
Capacity = 0;
return;
}
std::memcpy(Bits, RHS.Bits, Capacity * sizeof(BitWord));
}
-#if LLVM_HAS_RVALUE_REFERENCES
BitVector(BitVector &&RHS)
: Bits(RHS.Bits), Size(RHS.Size), Capacity(RHS.Capacity) {
- RHS.Bits = 0;
+ RHS.Bits = nullptr;
}
-#endif
~BitVector() {
std::free(Bits);
}
BitVector &set(unsigned Idx) {
- Bits[Idx / BITWORD_SIZE] |= 1L << (Idx % BITWORD_SIZE);
+ Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE);
return *this;
}
Bits[I / BITWORD_SIZE] = ~0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
- Bits[I / BITWORD_SIZE] |= PostfixMask;
+ if (I < E)
+ Bits[I / BITWORD_SIZE] |= PostfixMask;
return *this;
}
}
BitVector &reset(unsigned Idx) {
- Bits[Idx / BITWORD_SIZE] &= ~(1L << (Idx % BITWORD_SIZE));
+ Bits[Idx / BITWORD_SIZE] &= ~(BitWord(1) << (Idx % BITWORD_SIZE));
return *this;
}
Bits[I / BITWORD_SIZE] = 0UL;
BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1;
- Bits[I / BITWORD_SIZE] &= ~PostfixMask;
+ if (I < E)
+ Bits[I / BITWORD_SIZE] &= ~PostfixMask;
return *this;
}
}
BitVector &flip(unsigned Idx) {
- Bits[Idx / BITWORD_SIZE] ^= 1L << (Idx % BITWORD_SIZE);
+ Bits[Idx / BITWORD_SIZE] ^= BitWord(1) << (Idx % BITWORD_SIZE);
return *this;
}
bool operator[](unsigned Idx) const {
assert (Idx < Size && "Out-of-bounds Bit access.");
- BitWord Mask = 1L << (Idx % BITWORD_SIZE);
+ BitWord Mask = BitWord(1) << (Idx % BITWORD_SIZE);
return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
}
return *this;
}
-#if LLVM_HAS_RVALUE_REFERENCES
const BitVector &operator=(BitVector &&RHS) {
if (this == &RHS) return *this;
Size = RHS.Size;
Capacity = RHS.Capacity;
- RHS.Bits = 0;
+ RHS.Bits = nullptr;
return *this;
}
-#endif
void swap(BitVector &RHS) {
std::swap(Bits, RHS.Bits);