48#ifndef UTILS_OPENMDBITSET_HPP
49#define UTILS_OPENMDBITSET_HPP
66 OpenMDBitSet(
size_t nbits) : bitset_(nbits) {
clearAll(); }
73 void flip(
size_t bitIndex) { bitset_[bitIndex] = !bitset_[bitIndex]; }
77 void flip(
size_t fromIndex,
size_t toIndex);
83 bool get(
size_t bitIndex) {
return bitset_[bitIndex]; }
95 int firstOffBit()
const {
return !bitset_[0] ? 0 :
nextOffBit(0); }
102 int nthOffBit(
unsigned long int n)
const;
104 int firstOnBit()
const {
return bitset_[0] ? 0 :
nextOnBit(0); }
111 int nthOnBit(
unsigned long int n)
const;
123 void setBitOn(
size_t bitIndex) { setBit(bitIndex,
true); }
125 void setBitOff(
size_t bitIndex) { setBit(bitIndex,
false); }
127 void setRangeOn(
size_t fromIndex,
size_t toIndex) {
128 setBits(fromIndex, toIndex,
true);
131 void setRangeOff(
size_t fromIndex,
size_t toIndex) {
132 setBits(fromIndex, toIndex,
false);
138 void setAll() { setRangeOn(0,
size()); }
142 size_t size()
const {
return bitset_.size(); }
145 void resize(
size_t nbits);
151 OpenMDBitSet& operator|=(
const OpenMDBitSet& bs) {
155 OpenMDBitSet& operator^=(
const OpenMDBitSet& bs) {
159 OpenMDBitSet& operator-=(
const OpenMDBitSet& bs) {
160 OpenMDBitSet tmp = *
this ^ bs;
165 OpenMDBitSet parallelReduce();
167 bool operator[](
int bitIndex)
const {
return bitset_[bitIndex]; }
168 friend OpenMDBitSet operator|(
const OpenMDBitSet& bs1,
169 const OpenMDBitSet& bs2);
170 friend OpenMDBitSet operator&(
const OpenMDBitSet& bs1,
171 const OpenMDBitSet& bs2);
172 friend OpenMDBitSet operator^(
const OpenMDBitSet& bs1,
173 const OpenMDBitSet& bs2);
174 friend OpenMDBitSet operator-(
const OpenMDBitSet& bs1,
175 const OpenMDBitSet& bs2);
177 friend bool operator==(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2);
180 friend std::ostream& operator<<(std::ostream&,
const OpenMDBitSet& bs);
184 void setBit(
size_t bitIndex,
bool value) { bitset_[bitIndex] = value; }
188 void setBits(
size_t fromIndex,
size_t toIndex,
bool value);
190 std::vector<bool> bitset_;
OpenMDBitSet is a wrapper class of std::vector<bool> to act as a growable std::bitset.
bool any()
Returns true if any bits are set to true.
void andOperator(const OpenMDBitSet &bs)
Performs a logical AND of this target bit set with the argument bit set.
void clearAll()
Sets all of the bits in this OpenMDBitSet to false.
void flip(size_t bitIndex)
Sets the bit at the specified index to to the complement of its current value.
void flip()
Sets each bit to the complement of its current value.
bool none()
Returns true if no bits are set to true.
void resize(size_t nbits)
Changes the size of OpenMDBitSet.
int countBits()
Returns the number of bits set to true in this OpenMDBitSet.
size_t size() const
Returns the number of bits of space actually in use by this OpenMDBitSet to represent bit values.
int nextOnBit(int fromIndex) const
Returns the index of the first bit that is set to true that occurs on or after the specified starting...
bool get(size_t bitIndex)
Returns the value of the bit with the specified index.
void xorOperator(const OpenMDBitSet &bs)
Performs a logical XOR of this bit set with the bit set argument.
int nthOffBit(unsigned long int n) const
Returns the index of the n^th bit that is set to false.
int nextOffBit(int fromIndex) const
Returns the index of the first bit that is set to false that occurs on or after the specified startin...
void orOperator(const OpenMDBitSet &bs)
Performs a logical OR of this bit set with the bit set argument.
int nthOnBit(unsigned long int n) const
Returns the index of the n^th bit that is set to true.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.