[bitset] Don't visit bits in the tail end of the final word if they're beyond the nr bits in the bitset.

Also shift 1ULL in the test.
This commit is contained in:
Joe Thornber 2014-09-01 14:16:03 +01:00
parent 67865e0732
commit 14cfcf2dfd

View File

@ -82,7 +82,7 @@ namespace persistent_data {
}
void walk_bitset(bitset_visitor &v) const {
bit_visitor vv(v);
bit_visitor vv(v, nr_bits_);
damage_visitor dv(v);
array_.visit_values(vv, dv);
}
@ -90,18 +90,20 @@ namespace persistent_data {
private:
class bit_visitor {
public:
bit_visitor(bitset_visitor &v)
: v_(v) {
bit_visitor(bitset_visitor &v, unsigned nr_bits)
: v_(v),
nr_bits_(nr_bits) {
}
void visit(uint32_t word_index, uint64_t word) {
uint32_t bit_index = word_index * 64;
for (unsigned bit = 0; bit < 64; bit++, bit_index++)
v_.visit(bit_index, !!(word & (1 << bit)));
for (unsigned bit = 0; bit < 64 && bit_index < nr_bits_; bit++, bit_index++)
v_.visit(bit_index, !!(word & (1ULL << bit)));
}
private:
bitset_visitor &v_;
unsigned nr_bits_;
};
class damage_visitor {