mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +00:00
Fixed issue where BitSet didn't handle a range of 64 bits correctly on bulk operations - now just return the predefined MASK which has all the bits set when requesting that all the bits be set.
This commit is contained in:
parent
9c9ee5c26d
commit
7947981b4b
@ -34,8 +34,12 @@ public class BitSet implements Serializable, Cloneable {
|
|||||||
|
|
||||||
private static long getTrueMask(int fromIndex, int toIndex) {
|
private static long getTrueMask(int fromIndex, int toIndex) {
|
||||||
int currentRange = toIndex - fromIndex;
|
int currentRange = toIndex - fromIndex;
|
||||||
|
if (currentRange == 64) {
|
||||||
|
return MASK;
|
||||||
|
} else {
|
||||||
return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG));
|
return (((1L << currentRange) - 1L) << (fromIndex % BITS_PER_LONG));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BitSet(int bitLength) {
|
public BitSet(int bitLength) {
|
||||||
if (bitLength % BITS_PER_LONG == 0) {
|
if (bitLength % BITS_PER_LONG == 0) {
|
||||||
|
@ -96,6 +96,13 @@ public class BitsetTest {
|
|||||||
assertTrue("bit 2 should be 0", !bitset.get(2));
|
assertTrue("bit 2 should be 0", !bitset.get(2));
|
||||||
assertTrue("bit 3 should be 1", bitset.get(3));
|
assertTrue("bit 3 should be 1", bitset.get(3));
|
||||||
assertCardinality(bitset, 17);
|
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) {
|
static void assertTrue(String msg, boolean flag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user