lilzz wrote: Code: Select all
assert(i >= B && i < n + B);
size_t w = (i - B) / 64,
b = (i - B) & 63;
uint64_t m = ((uint64_t)1 << b);
return v[w] & m;
what it trying to do?
The bit vector is being stored as a vector of 64 bit ints. So if your vector contains less than 64 bits, it is stored as one 64 bit int.
B is the base of the vector (as described above).
w is the index into the member std::vector that holds the 64 bit integers. Divide by 64 as that is the number of bits held in each 64 bit integer. Subtract
B from
i to get rid of the base being used.
b is the bit number of bit to access in the 64 bit integer of interest. The value 63 is a mask, so that
b is in the range [0,63].
It is the remainder from the above division. It could have been written "b = (i - B) % 64"
m is a mask to access the b'th bit in the 64 bit integer of interest.
Finally the w'th 64 bit integer from the vector of integers used to implement the bit array is retrieved. Bitwise and is used to isolate the bit of interest from the retrieved 64 bit integer. The
bool type is either
true or
false. A non-zero integer value becomes
true, a zero value becomes
false. If the bit is a 1, then
true is returned. if the bit is a 0, the
false is returned.