Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/src/main/scala/org/apache/spark/util/collection/BitSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class BitSet(numBits: Int) extends Serializable {
}
}

/**
* Clear all the bits up to a given index
*/
def clearUntil(bitIndex: Int) {
val wordIndex = bitIndex >> 6 // divide by 64
var i = 0
while(i < wordIndex) { words(i) = 0; i += 1 }
if(wordIndex < words.length) {
// Set the remaining bits (note that the mask could still be zero)
val mask = ~(-1L << (bitIndex & 0x3f))
words(wordIndex) &= ~mask
}
}

/**
* Compute the bit-wise AND of the two sets returning the
* result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,36 @@ class BitSetSuite extends SparkFunSuite {
assert(bitsetDiff.nextSetBit(85) === 85)
assert(bitsetDiff.nextSetBit(86) === -1)
}

test( "[gs]etUntil" ) {
val bitSet = new BitSet(100)

bitSet.setUntil(bitSet.capacity)

(0 until bitSet.capacity).foreach { i =>
assert(bitSet.get(i))
}

bitSet.clearUntil(bitSet.capacity)

(0 until bitSet.capacity).foreach { i =>
assert(!bitSet.get(i))
}

val setUntil = bitSet.capacity / 2
bitSet.setUntil(setUntil)

val clearUntil = setUntil / 2
bitSet.clearUntil(clearUntil)

(0 until clearUntil).foreach { i =>
assert(!bitSet.get(i))
}
(clearUntil until setUntil).foreach { i =>
assert(bitSet.get(i))
}
(setUntil until bitSet.capacity).foreach { i =>
assert(!bitSet.get(i))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ private class SortMergeFullOuterJoinScanner(
}

if (leftMatches.size <= leftMatched.capacity) {
leftMatched.clear()
leftMatched.clearUntil(leftMatches.size)
} else {
leftMatched = new BitSet(leftMatches.size)
}
if (rightMatches.size <= rightMatched.capacity) {
rightMatched.clear()
rightMatched.clearUntil(rightMatches.size)
} else {
rightMatched = new BitSet(rightMatches.size)
}
Expand Down