Addressing bug in BitSet.setUntil(ind) where if invoked with a multiple of 64 could lead to an index out of bounds error.

This commit is contained in:
Joseph E. Gonzalez 2013-11-13 10:35:23 -08:00
parent 143c01dbd6
commit f0ef75c7a4

View file

@ -41,9 +41,11 @@ class BitSet(numBits: Int) {
val wordIndex = bitIndex >> 6 // divide by 64
var i = 0
while(i < wordIndex) { words(i) = -1; i += 1 }
// Set the remaining bits
val mask = ~(-1L << (bitIndex & 0x3f))
words(wordIndex) |= mask
if(wordIndex < words.size) {
// Set the remaining bits (note that the mask could still be zero)
val mask = ~(-1L << (bitIndex & 0x3f))
words(wordIndex) |= mask
}
}