45#include "selection/SelectionSet.hpp"
58 SelectionSet::SelectionSet(std::vector<int> nbits) {
59 bitsets_.resize(N_SELECTIONTYPES);
60 for (
int i = 0; i < N_SELECTIONTYPES; i++)
61 bitsets_[i] = OpenMDBitSet(nbits[i]);
66 std::vector<int> result(N_SELECTIONTYPES, 0);
67 for (
int i = 0; i < N_SELECTIONTYPES; i++)
73 for (
int i = 0; i < N_SELECTIONTYPES; i++)
74 bitsets_[i].
flip(bitIndex[i]);
78 std::vector<int> toIndex) {
79 for (
int i = 0; i < N_SELECTIONTYPES; i++)
80 bitsets_[i].
flip(fromIndex[i], toIndex[i]);
84 for (
int i = 0; i < N_SELECTIONTYPES; i++)
89 std::vector<bool> result(N_SELECTIONTYPES);
90 for (
int i = 0; i < N_SELECTIONTYPES; i++)
91 result[i] = bitsets_[i].
get(bitIndex[i]);
96 std::vector<int> toIndex) {
99 for (
int i = 0; i < N_SELECTIONTYPES; i++)
100 result.bitsets_[i] = bitsets_[i].get(fromIndex[i], toIndex[i]);
106 std::vector<bool> result(N_SELECTIONTYPES);
107 for (
int i = 0; i < N_SELECTIONTYPES; i++)
108 result[i] = bitsets_[i].
any();
113 std::vector<bool> result(N_SELECTIONTYPES);
114 for (
int i = 0; i < N_SELECTIONTYPES; i++)
115 result[i] = bitsets_[i].
none();
119 std::vector<int> SelectionSet::firstOffBit()
const {
120 std::vector<int> result(N_SELECTIONTYPES);
121 for (
int i = 0; i < N_SELECTIONTYPES; i++)
122 result[i] = bitsets_[i].firstOffBit();
127 std::vector<int> result(N_SELECTIONTYPES);
128 for (
int i = 0; i < N_SELECTIONTYPES; i++)
129 result[i] = bitsets_[i].
nextOffBit(fromIndex[i]);
133 std::vector<int> SelectionSet::firstOnBit()
const {
134 std::vector<int> result(N_SELECTIONTYPES);
135 for (
int i = 0; i < N_SELECTIONTYPES; i++)
136 result[i] = bitsets_[i].firstOnBit();
141 std::vector<int> result(N_SELECTIONTYPES);
142 for (
int i = 0; i < N_SELECTIONTYPES; i++)
143 result[i] = bitsets_[i].
nextOnBit(fromIndex[i]);
148 for (
int i = 0; i < N_SELECTIONTYPES; i++)
149 bitsets_[i] &= ss.bitsets_[i];
153 for (
int i = 0; i < N_SELECTIONTYPES; i++)
154 bitsets_[i] |= ss.bitsets_[i];
158 for (
int i = 0; i < N_SELECTIONTYPES; i++)
159 bitsets_[i] ^= ss.bitsets_[i];
169 for (
int i = 0; i < N_SELECTIONTYPES; i++)
173 void SelectionSet::setAll() {
174 for (
int i = 0; i < N_SELECTIONTYPES; i++)
175 bitsets_[i].setAll();
179 std::vector<int> result(N_SELECTIONTYPES);
180 for (
int i = 0; i < N_SELECTIONTYPES; i++)
181 result[i] = bitsets_[i].
size();
186 for (
int i = 0; i < N_SELECTIONTYPES; i++)
187 bitsets_[i].
resize(nbits[i]);
192 for (
int i = 0; i < N_SELECTIONTYPES; i++)
193 result.bitsets_[i] |= ss2.bitsets_[i];
197 SelectionSet operator&(
const SelectionSet& ss1,
const SelectionSet& ss2) {
198 SelectionSet result(ss1);
199 for (
int i = 0; i < N_SELECTIONTYPES; i++)
200 result.bitsets_[i] &= ss2.bitsets_[i];
204 SelectionSet operator^(
const SelectionSet& ss1,
const SelectionSet& ss2) {
205 SelectionSet result(ss1);
206 for (
int i = 0; i < N_SELECTIONTYPES; i++)
207 result.bitsets_[i] ^= ss2.bitsets_[i];
211 SelectionSet
operator-(
const SelectionSet& ss1,
const SelectionSet& ss2) {
212 SelectionSet result(ss1);
213 for (
int i = 0; i < N_SELECTIONTYPES; i++)
214 result.bitsets_[i] -= ss2.bitsets_[i];
218 bool operator==(
const SelectionSet& ss1,
const SelectionSet& ss2) {
219 for (
int i = 0; i < N_SELECTIONTYPES; i++) {
220 assert(ss1.bitsets_[i].size() == ss2.bitsets_[i].size());
221 if (!(ss1.bitsets_[i] == ss2.bitsets_[i]))
return false;
227 SelectionSet SelectionSet::parallelReduce() {
229 for (
int i = 0; i < N_SELECTIONTYPES; i++)
230 result.bitsets_[i] = bitsets_[i].parallelReduce();
240 std::ostream& operator<<(std::ostream& os,
const SelectionSet& ss) {
241 for (
int i = 0; i < N_SELECTIONTYPES; i++)
242 os <<
"SelectionSet[" << i <<
"] = " << ss.bitsets_[i] << std::endl;
std::vector< int > size() const
Returns the number of bits of space actually in use by this SelectionSet to represent bit values.
std::vector< int > nextOffBit(std::vector< int > fromIndex) const
Returns the index of the first bit that is set to false that occurs on or after the specified startin...
std::vector< bool > get(std::vector< int > bitIndex)
Returns the value of the bit with the specified index.
void clearAll()
Sets all of the bits in this SelectionSet to false.
void xorOperator(const SelectionSet &bs)
Performs a logical XOR of this bit set with the bit set argument.
void flip()
Sets each bit to the complement of its current value.
std::vector< int > countBits()
Returns the number of bits set to true in this SelectionSet.
std::vector< bool > none()
Returns true if no bits are set to true.
std::vector< int > nextOnBit(std::vector< int > fromIndex) const
Returns the index of the first bit that is set to true that occurs on or after the specified starting...
void andOperator(const SelectionSet &bs)
Performs a logical AND of this target bit set with the argument bit set.
void resize(std::vector< int > nbits)
Changes the size of SelectionSet.
void orOperator(const SelectionSet &bs)
Performs a logical OR of this bit set with the bit set argument.
std::vector< bool > any()
Returns true if any bits are 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.