48#include "utils/OpenMDBitSet.hpp"
63 return std::count(bitset_.begin(), bitset_.end(),
true);
67 assert(fromIndex <= toIndex);
68 assert(fromIndex >= 0);
69 assert(toIndex <=
size());
70 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
71 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
73 std::transform(first, last, first, std::logical_not<bool>());
77 assert(fromIndex <= toIndex);
78 assert(fromIndex >= 0);
79 assert(toIndex <=
size());
80 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
81 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
84 std::copy(first, last, std::back_inserter(result.bitset_));
89 std::vector<bool>::iterator i =
90 std::find(bitset_.begin(), bitset_.end(),
true);
91 return i == bitset_.end() ? true :
false;
95 if (fromIndex <= -1) {
101 while (fromIndex <
static_cast<int>(
size())) {
102 if (!bitset_[fromIndex]) {
return fromIndex; }
110 std::vector<int> indices;
111 for (
int i = firstOffBit(); i != -1; i =
nextOffBit(i)) {
112 indices.push_back(i);
115 if (n < indices.size())
return indices[n];
120 if (fromIndex <= -1) {
126 while (fromIndex <
static_cast<int>(
size())) {
127 if (bitset_[fromIndex]) {
return fromIndex; }
135 std::vector<int> indices;
136 for (
int i = firstOnBit(); i != -1; i =
nextOnBit(i)) {
137 indices.push_back(i);
140 if (n < indices.size())
return indices[n];
147 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
148 bitset_.begin(), std::logical_and<bool>());
153 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
154 bitset_.begin(), std::logical_or<bool>());
159 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
160 bitset_.begin(), std::bit_xor<bool>());
163 void OpenMDBitSet::setBits(
size_t fromIndex,
size_t toIndex,
bool value) {
164 assert(fromIndex <= toIndex);
165 assert(fromIndex >= 0);
166 assert(toIndex <=
size());
167 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
168 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
169 std::fill(first, last, value);
173 size_t oldSize =
size();
174 bitset_.resize(nbits);
175 if (nbits > oldSize) {
176 std::fill(bitset_.begin() + oldSize, bitset_.end(),
false);
188 OpenMDBitSet operator&(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2) {
189 assert(bs1.size() == bs2.size());
191 OpenMDBitSet result(bs1);
197 assert(bs1.size() == bs2.size());
205 assert(bs1.size() == bs2.size());
213 assert(bs1.size() == bs2.size());
214 return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(),
215 bs2.bitset_.begin());
229 std::vector<int> bsInt(bitset_.begin(), bitset_.end());
231 MPI_Allreduce(MPI_IN_PLACE, &bsInt[0], bsInt.size(), MPI_INT, MPI_LOR,
234 std::transform(bsInt.begin(), bsInt.end(),
235 std::back_inserter(result.bitset_),
236 [](
int val) { return val != 0; });
239 std::copy(bitset_.begin(), bitset_.end(),
240 std::back_inserter(result.bitset_));
251 std::ostream& operator<<(std::ostream& os,
const OpenMDBitSet& bs) {
252 for (
size_t i = 0; i < bs.bitset_.size(); ++i) {
253 std::string val = bs[i] ?
"true" :
"false";
254 os <<
"OpenMDBitSet[" << i <<
"] = " << val << std::endl;
OpenMDBitSet is a wrapper class of std::vector<bool> to act as a growable std::bitset.
void andOperator(const OpenMDBitSet &bs)
Performs a logical AND of this target bit set with the argument bit set.
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.
DynamicRectMatrix< Real > operator-(const DynamicRectMatrix< Real > &m)
Negate the value of every element of this matrix.