48#include "selection/SelectionSet.hpp"
61 SelectionSet::SelectionSet(std::vector<int> nbits) {
62 bitsets_.resize(N_SELECTIONTYPES);
63 for (
int i = 0; i < N_SELECTIONTYPES; i++)
64 bitsets_[i] = OpenMDBitSet(nbits[i]);
69 std::vector<int> result(N_SELECTIONTYPES, 0);
70 for (
int i = 0; i < N_SELECTIONTYPES; i++)
76 for (
int i = 0; i < N_SELECTIONTYPES; i++)
77 bitsets_[i].
flip(bitIndex[i]);
81 std::vector<int> toIndex) {
82 for (
int i = 0; i < N_SELECTIONTYPES; i++)
83 bitsets_[i].
flip(fromIndex[i], toIndex[i]);
87 for (
int i = 0; i < N_SELECTIONTYPES; i++)
92 std::vector<bool> result(N_SELECTIONTYPES);
93 for (
int i = 0; i < N_SELECTIONTYPES; i++)
94 result[i] = bitsets_[i].
get(bitIndex[i]);
99 std::vector<int> toIndex) {
102 for (
int i = 0; i < N_SELECTIONTYPES; i++)
103 result.bitsets_[i] = bitsets_[i].get(fromIndex[i], toIndex[i]);
109 std::vector<bool> result(N_SELECTIONTYPES);
110 for (
int i = 0; i < N_SELECTIONTYPES; i++)
111 result[i] = bitsets_[i].
any();
116 std::vector<bool> result(N_SELECTIONTYPES);
117 for (
int i = 0; i < N_SELECTIONTYPES; i++)
118 result[i] = bitsets_[i].
none();
122 std::vector<int> SelectionSet::firstOffBit()
const {
123 std::vector<int> result(N_SELECTIONTYPES);
124 for (
int i = 0; i < N_SELECTIONTYPES; i++)
125 result[i] = bitsets_[i].firstOffBit();
130 std::vector<int> result(N_SELECTIONTYPES);
131 for (
int i = 0; i < N_SELECTIONTYPES; i++)
132 result[i] = bitsets_[i].
nextOffBit(fromIndex[i]);
136 std::vector<int> SelectionSet::firstOnBit()
const {
137 std::vector<int> result(N_SELECTIONTYPES);
138 for (
int i = 0; i < N_SELECTIONTYPES; i++)
139 result[i] = bitsets_[i].firstOnBit();
144 std::vector<int> result(N_SELECTIONTYPES);
145 for (
int i = 0; i < N_SELECTIONTYPES; i++)
146 result[i] = bitsets_[i].
nextOnBit(fromIndex[i]);
151 for (
int i = 0; i < N_SELECTIONTYPES; i++)
152 bitsets_[i] &= ss.bitsets_[i];
156 for (
int i = 0; i < N_SELECTIONTYPES; i++)
157 bitsets_[i] |= ss.bitsets_[i];
161 for (
int i = 0; i < N_SELECTIONTYPES; i++)
162 bitsets_[i] ^= ss.bitsets_[i];
172 for (
int i = 0; i < N_SELECTIONTYPES; i++)
176 void SelectionSet::setAll() {
177 for (
int i = 0; i < N_SELECTIONTYPES; i++)
178 bitsets_[i].setAll();
182 std::vector<int> result(N_SELECTIONTYPES);
183 for (
int i = 0; i < N_SELECTIONTYPES; i++)
184 result[i] = bitsets_[i].
size();
189 for (
int i = 0; i < N_SELECTIONTYPES; i++)
190 bitsets_[i].
resize(nbits[i]);
195 for (
int i = 0; i < N_SELECTIONTYPES; i++)
196 result.bitsets_[i] |= ss2.bitsets_[i];
200 SelectionSet operator&(
const SelectionSet& ss1,
const SelectionSet& ss2) {
201 SelectionSet result(ss1);
202 for (
int i = 0; i < N_SELECTIONTYPES; i++)
203 result.bitsets_[i] &= ss2.bitsets_[i];
209 for (
int i = 0; i < N_SELECTIONTYPES; i++)
210 result.bitsets_[i] ^= ss2.bitsets_[i];
216 for (
int i = 0; i < N_SELECTIONTYPES; i++)
217 result.bitsets_[i] -= ss2.bitsets_[i];
222 for (
int i = 0; i < N_SELECTIONTYPES; i++) {
223 assert(ss1.bitsets_[i].size() == ss2.bitsets_[i].size());
224 if (!(ss1.bitsets_[i] == ss2.bitsets_[i]))
return false;
232 for (
int i = 0; i < N_SELECTIONTYPES; i++)
233 result.bitsets_[i] = bitsets_[i].parallelReduce();
243 std::ostream& operator<<(std::ostream& os,
const SelectionSet& ss) {
244 for (
int i = 0; i < N_SELECTIONTYPES; i++)
245 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.