| 42 |
|
#include "utils/BitSet.hpp" |
| 43 |
|
#include <algorithm> |
| 44 |
|
#include <cassert> |
| 45 |
< |
|
| 45 |
> |
#include <string> |
| 46 |
|
namespace oopse { |
| 47 |
|
int BitSet::countBits() { |
| 48 |
|
return std::count(bitset_.begin(), bitset_.end(), true); |
| 76 |
|
return i == bitset_.end() ? true : false; |
| 77 |
|
} |
| 78 |
|
|
| 79 |
< |
int BitSet::nextOffBit(int fromIndex) { |
| 79 |
> |
int BitSet::nextOffBit(int fromIndex) const { |
| 80 |
|
++fromIndex; |
| 81 |
|
while (fromIndex < size()) { |
| 82 |
|
if (!bitset_[fromIndex]) { |
| 88 |
|
return -1; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
< |
int BitSet::nextOnBit(int fromIndex) { |
| 91 |
> |
int BitSet::nextOnBit(int fromIndex) const { |
| 92 |
|
++fromIndex; |
| 93 |
|
while (fromIndex < size()) { |
| 94 |
|
if (bitset_[fromIndex]) { |
| 125 |
|
std::fill(first, last, value); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
+ |
void BitSet::resize(int nbits) { |
| 129 |
+ |
int oldSize = size(); |
| 130 |
+ |
bitset_.resize(nbits); |
| 131 |
+ |
if (nbits > oldSize) { |
| 132 |
+ |
std::fill(bitset_.begin()+oldSize, bitset_.begin()+nbits+1, false); |
| 133 |
+ |
} |
| 134 |
+ |
} |
| 135 |
+ |
|
| 136 |
|
BitSet operator| (const BitSet& bs1, const BitSet& bs2) { |
| 137 |
|
assert(bs1.size() == bs2.size()); |
| 138 |
|
|
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
std::ostream& operator<< ( std::ostream& os, const BitSet& bs) { |
| 171 |
+ |
for (int i = 0; i < bs.bitset_.size(); ++i) { |
| 172 |
+ |
std::string val = bs[i] ? "true" : "false"; |
| 173 |
+ |
os << "BitSet[" << i <<"] = " << val << std::endl; |
| 174 |
+ |
} |
| 175 |
+ |
|
| 176 |
|
return os; |
| 177 |
|
} |
| 178 |
|
|