aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/org/apache/spark/util/collection/BitSet.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/org/apache/spark/util/collection/BitSet.scala')
-rw-r--r--core/src/main/scala/org/apache/spark/util/collection/BitSet.scala39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/collection/BitSet.scala b/core/src/main/scala/org/apache/spark/util/collection/BitSet.scala
index d3153d2cac..af1f64649f 100644
--- a/core/src/main/scala/org/apache/spark/util/collection/BitSet.scala
+++ b/core/src/main/scala/org/apache/spark/util/collection/BitSet.scala
@@ -89,6 +89,45 @@ class BitSet(numBits: Int) extends Serializable {
}
/**
+ * Compute the symmetric difference by performing bit-wise XOR of the two sets returning the
+ * result.
+ */
+ def ^(other: BitSet): BitSet = {
+ val newBS = new BitSet(math.max(capacity, other.capacity))
+ val smaller = math.min(numWords, other.numWords)
+ var ind = 0
+ while (ind < smaller) {
+ newBS.words(ind) = words(ind) ^ other.words(ind)
+ ind += 1
+ }
+ if (ind < numWords) {
+ Array.copy( words, ind, newBS.words, ind, numWords - ind )
+ }
+ if (ind < other.numWords) {
+ Array.copy( other.words, ind, newBS.words, ind, other.numWords - ind )
+ }
+ newBS
+ }
+
+ /**
+ * Compute the difference of the two sets by performing bit-wise AND-NOT returning the
+ * result.
+ */
+ def andNot(other: BitSet): BitSet = {
+ val newBS = new BitSet(capacity)
+ val smaller = math.min(numWords, other.numWords)
+ var ind = 0
+ while (ind < smaller) {
+ newBS.words(ind) = words(ind) & ~other.words(ind)
+ ind += 1
+ }
+ if (ind < numWords) {
+ Array.copy( words, ind, newBS.words, ind, numWords - ind )
+ }
+ newBS
+ }
+
+ /**
* Sets the bit at the specified index to true.
* @param index the bit index
*/