| 39 |
|
* such damages. |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
– |
#include "utils/BitSet.hpp" |
| 42 |
|
#include <algorithm> |
| 43 |
|
#include <cassert> |
| 44 |
+ |
#include <string> |
| 45 |
|
|
| 46 |
+ |
#include "utils/BitSet.hpp" |
| 47 |
+ |
#include "utils/Algorithm.hpp" |
| 48 |
+ |
|
| 49 |
|
namespace oopse { |
| 50 |
|
int BitSet::countBits() { |
| 51 |
|
return std::count(bitset_.begin(), bitset_.end(), true); |
| 79 |
|
return i == bitset_.end() ? true : false; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
< |
int BitSet::nextOffBit(int fromIndex) { |
| 82 |
> |
int BitSet::nextOffBit(int fromIndex) const { |
| 83 |
|
++fromIndex; |
| 84 |
|
while (fromIndex < size()) { |
| 85 |
|
if (!bitset_[fromIndex]) { |
| 91 |
|
return -1; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
< |
int BitSet::nextOnBit(int fromIndex) { |
| 94 |
> |
int BitSet::nextOnBit(int fromIndex) const { |
| 95 |
|
++fromIndex; |
| 96 |
|
while (fromIndex < size()) { |
| 97 |
|
if (bitset_[fromIndex]) { |
| 128 |
|
std::fill(first, last, value); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
+ |
void BitSet::resize(int nbits) { |
| 132 |
+ |
int oldSize = size(); |
| 133 |
+ |
bitset_.resize(nbits); |
| 134 |
+ |
if (nbits > oldSize) { |
| 135 |
+ |
std::fill(bitset_.begin()+oldSize, bitset_.begin()+nbits+1, false); |
| 136 |
+ |
} |
| 137 |
+ |
} |
| 138 |
+ |
|
| 139 |
|
BitSet operator| (const BitSet& bs1, const BitSet& bs2) { |
| 140 |
|
assert(bs1.size() == bs2.size()); |
| 141 |
|
|
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
std::ostream& operator<< ( std::ostream& os, const BitSet& bs) { |
| 174 |
+ |
for (int i = 0; i < bs.bitset_.size(); ++i) { |
| 175 |
+ |
std::string val = bs[i] ? "true" : "false"; |
| 176 |
+ |
os << "BitSet[" << i <<"] = " << val << std::endl; |
| 177 |
+ |
} |
| 178 |
+ |
|
| 179 |
|
return os; |
| 180 |
|
} |
| 181 |
|
|