Strange issue with a Bitset of size 64 (cardinality always 0)
Closed this issue · 3 comments
kevinjalbert commented
If you have a Bitset of size 64, you get an incorrect cardinality value (always 0).
bits = Bitset.new(64)
bits.set(13,23)
puts bits.cardinality
Results in the value of 0, when it should be 2.
brendon9x commented
This occurs with all Bitsets that have sizes that are multiples of 64. Bits set in the final word will not be counted.
For example:
a = Bitset.new(128)
a[65] = 1
a.cardinality #= prints 0
Error down to this line:
if(i+1 == max)
segment &= ((((uint64_t) 1) << (bs->len & 0x3F)) - 1)
Substituting bs->len for any multiple of 64 results in segment &= 0
This is a bit beyond my comfort zone. I'd suggest a modulo check, but the source looks like it's geared for speed.
brendon9x commented
Perhaps if(i+1 == max && (bs->len & 0x3F))
?
kevinjalbert commented
I'm closing this issue as a great deal of time has passed. If there is renewed interest just reopen or make a new issue and link to this one.