Permalink
Browse files

Fixed issue where BitSet didn't handle a range of 64 bits correctly o…

…n bulk operations - now just return the predefined MASK which has all the bits set when requesting that all the bits be set.
  • Loading branch information...
1 parent 9c9ee5c commit 7947981b4b4d6055ffad4b9430aa6e60ef93f2d0 @mkeesey mkeesey committed Jul 7, 2012
Showing with 12 additions and 1 deletion.
  1. +5 −1 classpath/java/util/BitSet.java
  2. +7 −0 test/BitsetTest.java
@@ -34,7 +34,11 @@ private static long bitPosition(int index) {
private static long getTrueMask(int fromIndex, int toIndex) {
int currentRange = toIndex - fromIndex;
- return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG));
+ if (currentRange == 64) {
+ return MASK;
+ } else {
+ return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG));
+ }
}
public BitSet(int bitLength) {
View
@@ -96,6 +96,13 @@ private static void testClear() {
assertTrue("bit 2 should be 0", !bitset.get(2));
assertTrue("bit 3 should be 1", bitset.get(3));
assertCardinality(bitset, 17);
+
+ bitset = new BitSet(70);
+ bitset.flip(0, 65);
+ for (int i=0; i < 65; ++i) {
+ assertTrue("bit " + i + " should be set", bitset.get(i));
+ }
+ assertTrue("bit 65 should not be set", !bitset.get(65));
}
static void assertTrue(String msg, boolean flag) {

0 comments on commit 7947981

Please sign in to comment.