| 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 | + | #ifdef __RWSTD | 
| 52 | + | //For the compiler(Sun, MSVC6.0) binding with RougeWave STL Library, we need to use old-style | 
| 53 | + | // std::count which is error-prone. | 
| 54 | + | int count = 0; | 
| 55 | + | std::count(bitset_.begin(), bitset_.end(), true, count); | 
| 56 | + | return count; | 
| 57 | + | #else | 
| 58 |  | return std::count(bitset_.begin(), bitset_.end(), true); | 
| 59 | + | #endif | 
| 60 |  | } | 
| 61 |  |  | 
| 62 |  | void BitSet::flip(int fromIndex, int toIndex) { | 
| 88 |  | } | 
| 89 |  |  | 
| 90 |  | int BitSet::nextOffBit(int fromIndex) const { | 
| 91 | + | if (fromIndex <= -1) { | 
| 92 | + | //in case -1 or other negative number is passed to this function | 
| 93 | + | return -1; | 
| 94 | + | } | 
| 95 | + |  | 
| 96 |  | ++fromIndex; | 
| 97 |  | while (fromIndex < size()) { | 
| 98 |  | if (!bitset_[fromIndex]) { | 
| 105 |  | } | 
| 106 |  |  | 
| 107 |  | int BitSet::nextOnBit(int fromIndex) const { | 
| 108 | + | if (fromIndex <= -1) { | 
| 109 | + | //in case -1 or other negative number is passed to this function | 
| 110 | + | return -1; | 
| 111 | + | } | 
| 112 | + |  | 
| 113 |  | ++fromIndex; | 
| 114 |  | while (fromIndex < size()) { | 
| 115 |  | if (bitset_[fromIndex]) { | 
| 150 |  | int oldSize = size(); | 
| 151 |  | bitset_.resize(nbits); | 
| 152 |  | if (nbits > oldSize) { | 
| 153 | < | std::fill(bitset_.begin()+oldSize, bitset_.begin()+nbits+1, false); | 
| 153 | > | std::fill(bitset_.begin()+oldSize, bitset_.end(), false); | 
| 154 |  | } | 
| 155 |  | } | 
| 156 |  |  | 
| 178 |  | return result; | 
| 179 |  | } | 
| 180 |  |  | 
| 181 | + | BitSet operator- (const BitSet& bs1, const BitSet& bs2) { | 
| 182 | + | assert(bs1.size() == bs2.size()); | 
| 183 | + |  | 
| 184 | + | BitSet result(bs1); | 
| 185 | + | result -= bs2; | 
| 186 | + | return result; | 
| 187 | + | } | 
| 188 | + |  | 
| 189 |  | bool operator== (const BitSet & bs1, const BitSet &bs2) { | 
| 190 |  | assert(bs1.size() == bs2.size()); | 
| 191 |  | return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(), bs2.bitset_.begin()); | 
| 192 |  | } | 
| 193 |  |  | 
| 194 | < | std::istream& operator>> ( std::istream& is, const BitSet& bs) { | 
| 194 | > | //std::istream& operator>> ( std::istream& is, const BitSet& bs) { | 
| 195 | > | // | 
| 196 | > | //    return is; | 
| 197 | > | //} | 
| 198 |  |  | 
| 167 | – | return is; | 
| 168 | – | } | 
| 169 | – |  | 
| 199 |  | std::ostream& operator<< ( std::ostream& os, const BitSet& bs) { | 
| 200 |  | for (int i = 0; i < bs.bitset_.size(); ++i) { | 
| 201 |  | std::string val = bs[i] ? "true" : "false"; |