14 template<
class BMType>
20 template<
class BMType>
24 result._lo = BitMaskType::all_on();
25 result._hi = BitMaskType::all_on();
32 template<
class BMType>
44 template<
class BMType>
49 }
else if (on_bits >= num_bits) {
53 if (on_bits <= half_bits) {
54 result._lo = BitMaskType::lower_on(on_bits);
56 result._lo = BitMaskType::all_on();
57 result._hi = BitMaskType::lower_on(on_bits - half_bits);
65 template<
class BMType>
76 template<
class BMType>
78 range(
int low_bit,
int size) {
87 template<
class BMType>
97 template<
class BMType>
100 if (index < half_bits) {
101 return _lo.get_bit(index);
103 return _hi.get_bit(index - half_bits);
110 template<
class BMType>
113 if (index < half_bits) {
116 _hi.set_bit(index - half_bits);
123 template<
class BMType>
126 if (index < half_bits) {
127 _lo.clear_bit(index);
129 _hi.clear_bit(index - half_bits);
137 template<
class BMType>
140 if (index < half_bits) {
141 _lo.set_bit_to(index, value);
143 _hi.set_bit_to(index - half_bits, value);
150 template<
class BMType>
153 return (_lo.is_zero() && _hi.is_zero());
159 template<
class BMType>
162 return (_lo.is_all_on() && _hi.is_all_on());
169 template<
class BMType>
171 extract(
int low_bit,
int size)
const {
172 if (low_bit >= half_bits) {
173 return _hi.extract(low_bit - half_bits, size);
174 }
else if (low_bit + size < half_bits) {
175 return _lo.extract(low_bit, size);
177 int hi_portion = low_bit + size - half_bits;
178 int lo_portion = size - hi_portion;
179 return (_hi.extract(0, hi_portion) << lo_portion) |
180 _lo.extract(low_bit, lo_portion);
188 template<
class BMType>
190 store(WordType value,
int low_bit,
int size) {
191 if (low_bit >= half_bits) {
192 _hi.store(value, low_bit - half_bits, size);
193 }
else if (low_bit + size < half_bits) {
194 _lo.store(value, low_bit, size);
196 int hi_portion = low_bit + size - half_bits;
197 int lo_portion = size - hi_portion;
199 _hi.store(value >> lo_portion, 0, hi_portion);
200 _lo.store(value, low_bit, lo_portion);
207 template<
class BMType>
210 if (low_bit >= half_bits) {
211 return _hi.has_any_of(low_bit - half_bits, size);
212 }
else if (low_bit + size < half_bits) {
213 return _lo.has_any_of(low_bit, size);
215 int hi_portion = low_bit + size - half_bits;
216 int lo_portion = size - hi_portion;
217 return _hi.has_any_of(0, hi_portion)
218 || _lo.has_any_of(low_bit, lo_portion);
225 template<
class BMType>
228 if (low_bit >= half_bits) {
229 return _hi.has_all_of(low_bit - half_bits, size);
230 }
else if (low_bit + size < half_bits) {
231 return _lo.has_all_of(low_bit, size);
233 int hi_portion = low_bit + size - half_bits;
234 int lo_portion = size - hi_portion;
235 return _hi.has_all_of(0, hi_portion)
236 && _lo.has_all_of(low_bit, lo_portion);
243 template<
class BMType>
246 if (low_bit >= half_bits) {
247 _hi.set_range(low_bit - half_bits, size);
248 }
else if (low_bit + size < half_bits) {
249 _lo.set_range(low_bit, size);
251 int hi_portion = low_bit + size - half_bits;
252 int lo_portion = size - hi_portion;
254 _hi.set_range(0, hi_portion);
255 _lo.set_range(low_bit, lo_portion);
262 template<
class BMType>
265 if (low_bit >= half_bits) {
266 _hi.clear_range(low_bit - half_bits, size);
267 }
else if (low_bit + size < half_bits) {
268 _lo.clear_range(low_bit, size);
270 int hi_portion = low_bit + size - half_bits;
271 int lo_portion = size - hi_portion;
273 _hi.clear_range(0, hi_portion);
274 _lo.clear_range(low_bit, lo_portion);
281 template<
class BMType>
285 set_range(low_bit, size);
287 clear_range(low_bit, size);
294 template<
class BMType>
297 return _lo.get_num_on_bits() + _hi.get_num_on_bits();
303 template<
class BMType>
306 return _lo.get_num_off_bits() + _hi.get_num_off_bits();
313 template<
class BMType>
316 int result = _lo.get_lowest_on_bit();
318 result = _hi.get_lowest_on_bit();
330 template<
class BMType>
333 int result = _lo.get_lowest_off_bit();
335 result = _hi.get_lowest_off_bit();
347 template<
class BMType>
350 int result = _hi.get_highest_on_bit();
352 result = _lo.get_highest_on_bit();
363 template<
class BMType>
366 int result = _hi.get_highest_off_bit();
368 result = _lo.get_highest_off_bit();
382 template<
class BMType>
385 if (low_bit > half_bits) {
386 return _hi.get_next_higher_different_bit(low_bit - half_bits) + half_bits;
388 int result = _lo.get_next_higher_different_bit(low_bit);
389 if (result != low_bit) {
392 if (_lo.get_bit(low_bit)) {
393 result = _hi.get_lowest_off_bit();
395 result = _hi.get_lowest_on_bit();
400 return result + half_bits;
407 template<
class BMType>
410 _lo.invert_in_place();
411 _hi.invert_in_place();
422 template<
class BMType>
425 return _lo.has_bits_in_common(other._lo) ||
426 _hi.has_bits_in_common(other._hi);
432 template<
class BMType>
443 template<
class BMType>
445 output(std::ostream &out)
const {
453 template<
class BMType>
456 _hi.output_binary(out);
458 _lo.output_binary(out);
465 template<
class BMType>
467 output_hex(std::ostream &out,
int spaces_every)
const {
477 template<
class BMType>
479 write(std::ostream &out,
int indent_level)
const {
480 indent(out, indent_level) << *
this <<
"\n";
486 template<
class BMType>
489 return _lo == other._lo && _hi == other._hi;
495 template<
class BMType>
498 return _lo != other._lo && _hi != other._hi;
508 template<
class BMType>
511 int cmp = _hi.compare_to(other._hi);
515 return _lo < other._lo;
524 template<
class BMType>
527 int cmp = _hi.compare_to(other._hi);
531 return _lo.compare_to(other._lo);
537 template<
class BMType>
548 template<
class BMType>
559 template<
class BMType>
570 template<
class BMType>
574 result.invert_in_place();
581 template<
class BMType>
592 template<
class BMType>
603 template<
class BMType>
613 template<
class BMType>
623 template<
class BMType>
633 template<
class BMType>
636 _hi = (_hi << shift) | ((_lo >> (half_bits - shift)) & BitMaskType::lower_on(shift));
643 template<
class BMType>
646 _lo = (_lo >> shift) | ((_hi & BitMaskType::lower_on(shift)) << (half_bits - shift));
653 template<
class BMType>
656 _hi.generate_hash(hashgen);
657 _lo.generate_hash(hashgen);
663 template<
class BMType>
666 std::ostringstream str;
667 str <<
"DoubleBitMask" << num_bits;