Skip to content

Commit 473bf9d

Browse files
committed
Address Josh's review comments
1 parent 1719c5b commit 473bf9d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

unsafe/src/main/java/org/apache/spark/unsafe/bitset/BitSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public int nextSetBit(int fromIndex) {
107107
* @return whether any bit in the BitSet is set
108108
*/
109109
public boolean anySet() {
110-
return BitSetMethods.anySet(baseObject, baseOffset, numWords*BitSetMethods.WORD_SIZE);
110+
return BitSetMethods.anySet(baseObject, baseOffset, numWords);
111111
}
112112

113113
}

unsafe/src/main/java/org/apache/spark/unsafe/bitset/BitSetMethods.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ public static boolean isSet(Object baseObject, long baseOffset, int index) {
7070
/**
7171
* Returns {@code true} if any bit is set.
7272
*/
73-
public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidthInBytes) {
74-
assert bitSetWidthInBytes % WORD_SIZE == 0;
75-
int widthInLong = (int)(bitSetWidthInBytes / WORD_SIZE);
73+
public static boolean anySet(Object baseObject, long baseOffset, long bitSetWidthInWords) {
7674
long addr = baseOffset;
77-
for (int i = 0; i < widthInLong; i++, addr += WORD_SIZE) {
75+
for (int i = 0; i < bitSetWidthInWords; i++, addr += WORD_SIZE) {
7876
if (PlatformDependent.UNSAFE.getLong(baseObject, addr) != 0) {
7977
return true;
8078
}

unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void basicOps() {
3939
for (int i = 0; i < bs.capacity(); i++) {
4040
Assert.assertFalse(bs.isSet(i));
4141
}
42+
// another form of asserting that the bit set is empty
4243
Assert.assertFalse(bs.anySet());
4344

4445
// Set every bit and check it.
@@ -53,6 +54,11 @@ public void basicOps() {
5354
bs.unset(i);
5455
Assert.assertFalse(bs.isSet(i));
5556
}
57+
58+
// Make sure anySet() can detect any set bit
59+
bs = createBitSet(256);
60+
bs.set(64);
61+
Assert.assertTrue(bs.anySet());
5662
}
5763

5864
@Test

0 commit comments

Comments
 (0)