Fixed an off-by-one error when deciding if we should grow BitSets.

This commit is contained in:
Mike Keesey
2012-07-03 21:28:59 -06:00
parent bc1c797911
commit 5f1b086150
2 changed files with 7 additions and 3 deletions

View File

@ -105,9 +105,9 @@ public class BitSet implements Serializable, Cloneable {
} }
} }
private void enlarge(int newSize) { private void enlarge(int newPartition) {
if (bits == null || bits.length < newSize) { if (bits == null || bits.length < (newPartition + 1)) {
long[] newBits = new long[newSize + 1]; long[] newBits = new long[newPartition + 1];
if (bits != null) { if (bits != null) {
System.arraycopy(bits, 0, newBits, 0, bits.length); System.arraycopy(bits, 0, newBits, 0, bits.length);
} }

View File

@ -48,6 +48,10 @@ public class BitsetTest {
assertEquals("after 100, 102 is empty", 102, bits.nextClearBit(100)); assertEquals("after 100, 102 is empty", 102, bits.nextClearBit(100));
testFlip(); testFlip();
BitSet expandingSet = new BitSet();
//should force us to have 3 partitions.
expandingSet.set(128);
} }
private static void testFlip() { private static void testFlip() {