# | Line 42 | Line 42 | |
---|---|---|
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); | |
# | Line 76 | Line 76 | bool BitSet::none() { | |
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]) { | |
# | Line 88 | Line 88 | int BitSet::nextOffBit(int 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]) { | |
# | Line 125 | Line 125 | void BitSet::setBits(int fromIndex, int toIndex, bool | |
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 | ||
# | Line 160 | Line 168 | std::ostream& operator<< ( std::ostream& os, const Bit | |
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 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |