45#include "utils/OpenMDBitSet.hpp"
60 return std::count(bitset_.begin(), bitset_.end(),
true);
64 assert(fromIndex <= toIndex);
65 assert(fromIndex >= 0);
66 assert(toIndex <=
size());
67 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
68 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
70 std::transform(first, last, first, std::logical_not<bool>());
74 assert(fromIndex <= toIndex);
75 assert(fromIndex >= 0);
76 assert(toIndex <=
size());
77 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
78 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
81 std::copy(first, last, std::back_inserter(result.bitset_));
86 std::vector<bool>::iterator i =
87 std::find(bitset_.begin(), bitset_.end(),
true);
88 return i == bitset_.end() ? true :
false;
92 if (fromIndex <= -1) {
98 while (fromIndex <
static_cast<int>(
size())) {
99 if (!bitset_[fromIndex]) {
return fromIndex; }
107 std::vector<int> indices;
108 for (
int i = firstOffBit(); i != -1; i =
nextOffBit(i)) {
109 indices.push_back(i);
112 if (n < indices.size())
return indices[n];
117 if (fromIndex <= -1) {
123 while (fromIndex <
static_cast<int>(
size())) {
124 if (bitset_[fromIndex]) {
return fromIndex; }
132 std::vector<int> indices;
133 for (
int i = firstOnBit(); i != -1; i =
nextOnBit(i)) {
134 indices.push_back(i);
137 if (n < indices.size())
return indices[n];
144 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
145 bitset_.begin(), std::logical_and<bool>());
150 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
151 bitset_.begin(), std::logical_or<bool>());
156 std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(),
157 bitset_.begin(), std::bit_xor<bool>());
160 void OpenMDBitSet::setBits(
size_t fromIndex,
size_t toIndex,
bool value) {
161 assert(fromIndex <= toIndex);
162 assert(fromIndex >= 0);
163 assert(toIndex <=
size());
164 std::vector<bool>::iterator first = bitset_.begin() + fromIndex;
165 std::vector<bool>::iterator last = bitset_.begin() + toIndex;
166 std::fill(first, last, value);
170 size_t oldSize =
size();
171 bitset_.resize(nbits);
172 if (nbits > oldSize) {
173 std::fill(bitset_.begin() + oldSize, bitset_.end(),
false);
185 OpenMDBitSet operator&(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2) {
186 assert(bs1.size() == bs2.size());
188 OpenMDBitSet result(bs1);
193 OpenMDBitSet operator^(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2) {
194 assert(bs1.size() == bs2.size());
196 OpenMDBitSet result(bs1);
201 OpenMDBitSet
operator-(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2) {
202 assert(bs1.size() == bs2.size());
204 OpenMDBitSet result(bs1);
209 bool operator==(
const OpenMDBitSet& bs1,
const OpenMDBitSet& bs2) {
210 assert(bs1.size() == bs2.size());
211 return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(),
212 bs2.bitset_.begin());
215 OpenMDBitSet OpenMDBitSet::parallelReduce() {
226 std::vector<int> bsInt(bitset_.begin(), bitset_.end());
228 MPI_Allreduce(MPI_IN_PLACE, &bsInt[0], bsInt.size(), MPI_INT, MPI_LOR,
231 std::transform(bsInt.begin(), bsInt.end(),
232 std::back_inserter(result.bitset_),
233 [](
int val) { return val != 0; });
236 std::copy(bitset_.begin(), bitset_.end(),
237 std::back_inserter(result.bitset_));
248 std::ostream& operator<<(std::ostream& os,
const OpenMDBitSet& bs) {
249 for (
size_t i = 0; i < bs.bitset_.size(); ++i) {
250 std::string val = bs[i] ?
"true" :
"false";
251 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.