# | Line 41 | Line 41 | |
---|---|---|
41 | ||
42 | #include "utils/BitSet.hpp" | |
43 | #include <algorithm> | |
44 | + | #include <cassert> |
45 | + | |
46 | namespace oopse { | |
47 | int BitSet::countBits() { | |
48 | < | std::count(bitset_.begin(), bitset_.end(), true); |
48 | > | return std::count(bitset_.begin(), bitset_.end(), true); |
49 | } | |
50 | ||
51 | void BitSet::flip(int fromIndex, int toIndex) { | |
# | Line 69 | Line 71 | BitSet BitSet::get(int fromIndex, int toIndex) { | |
71 | return result; | |
72 | } | |
73 | ||
74 | < | bool BitSet::isEmpty() { |
74 | > | bool BitSet::none() { |
75 | std::vector<char>::iterator i = std::find(bitset_.begin(), bitset_.end(), true); | |
76 | return i == bitset_.end() ? true : false; | |
77 | } | |
78 | ||
79 | int BitSet::nextOffBit(int fromIndex) { | |
80 | + | ++fromIndex; |
81 | + | while (fromIndex < size()) { |
82 | + | if (!bitset_[fromIndex]) { |
83 | + | return fromIndex; |
84 | + | } |
85 | + | ++fromIndex; |
86 | + | } |
87 | ||
88 | + | return -1; |
89 | } | |
90 | ||
91 | < | int BitSet::nextOnBit(int fromIndex); |
91 | > | int BitSet::nextOnBit(int fromIndex) { |
92 | > | ++fromIndex; |
93 | > | while (fromIndex < size()) { |
94 | > | if (bitset_[fromIndex]) { |
95 | > | return fromIndex; |
96 | > | } |
97 | > | ++fromIndex; |
98 | > | } |
99 | ||
100 | < | void BitSet::and(const BitSet& bs) { |
100 | > | return -1; |
101 | > | } |
102 | > | |
103 | > | void BitSet::andOperator (const BitSet& bs) { |
104 | assert(size() == bs.size()); | |
105 | ||
106 | std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(), bitset_.begin(), std::logical_and<bool>()); | |
107 | } | |
108 | ||
109 | < | void BitSet::andNot(const BitSet& bs) { |
109 | > | void BitSet::orOperator (const BitSet& bs) { |
110 | assert(size() == bs.size()); | |
91 | – | std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(), bitset_.begin(), oopse::logical_andNot<bool>()); |
92 | – | } |
93 | – | |
94 | – | void BitSet::or(const BitSet& bs){ |
95 | – | assert(size() == bs.size()); |
111 | std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(), bitset_.begin(), std::logical_or<bool>()); | |
112 | } | |
113 | ||
114 | < | void BitSet::xor(const BitSet& bs); { |
114 | > | void BitSet::xorOperator (const BitSet& bs) { |
115 | assert(size() == bs.size()); | |
116 | std::transform(bs.bitset_.begin(), bs.bitset_.end(), bitset_.begin(), bitset_.begin(), oopse::logical_xor<bool>()); | |
117 | } | |
# | Line 110 | Line 125 | void BitSet::setBits(int fromIndex, int toIndex, bool | |
125 | std::fill(first, last, value); | |
126 | } | |
127 | ||
128 | < | BitSet operator| (BitSet& bs1, BitSet& bs2) { |
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 | ||
139 | BitSet result(bs1); | |
# | Line 118 | Line 141 | BitSet operator| (BitSet& bs1, BitSet& bs2) { | |
141 | return result; | |
142 | } | |
143 | ||
144 | < | BitSet operator& (BitSet& bs1, BitSet& bs2) { |
144 | > | BitSet operator& (const BitSet& bs1, const BitSet& bs2) { |
145 | assert(bs1.size() == bs2.size()); | |
146 | ||
147 | BitSet result(bs1); | |
# | Line 126 | Line 149 | BitSet operator& (BitSet& bs1, BitSet& bs2) { | |
149 | return result; | |
150 | } | |
151 | ||
152 | < | BitSet operator^ (BitSet& bs1, BitSet& bs2) { |
152 | > | BitSet operator^ (const BitSet& bs1, const BitSet& bs2) { |
153 | assert(bs1.size() == bs2.size()); | |
154 | ||
155 | BitSet result(bs1); | |
# | Line 139 | Line 162 | bool operator== (const BitSet & bs1, const BitSet &bs2 | |
162 | return std::equal(bs1.bitset_.begin(), bs1.bitset_.end(), bs2.bitset_.begin()); | |
163 | } | |
164 | ||
165 | < | std::istream& operator>> ( std::istream& is, BitSet& bs) { |
165 | > | std::istream& operator>> ( std::istream& is, const BitSet& bs) { |
166 | ||
167 | + | return is; |
168 | } | |
169 | ||
170 | std::ostream& operator<< ( std::ostream& os, const BitSet& bs) { | |
171 | < | |
171 | > | return os; |
172 | } | |
173 | ||
174 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |