aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala12
1 files changed, 11 insertions, 1 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala b/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala
index 1501111a06..64e7102e36 100644
--- a/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala
+++ b/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala
@@ -20,6 +20,8 @@ package org.apache.spark.util.collection
import scala.reflect._
import com.google.common.hash.Hashing
+import org.apache.spark.annotation.Private
+
/**
* A simple, fast hash set optimized for non-null insertion-only use case, where keys are never
* removed.
@@ -37,7 +39,7 @@ import com.google.common.hash.Hashing
* It uses quadratic probing with a power-of-2 hash table size, which is guaranteed
* to explore all spaces for each key (see http://en.wikipedia.org/wiki/Quadratic_probing).
*/
-private[spark]
+@Private
class OpenHashSet[@specialized(Long, Int) T: ClassTag](
initialCapacity: Int,
loadFactor: Double)
@@ -110,6 +112,14 @@ class OpenHashSet[@specialized(Long, Int) T: ClassTag](
rehashIfNeeded(k, grow, move)
}
+ def union(other: OpenHashSet[T]): OpenHashSet[T] = {
+ val iterator = other.iterator
+ while (iterator.hasNext) {
+ add(iterator.next())
+ }
+ this
+ }
+
/**
* Add an element to the set. This one differs from add in that it doesn't trigger rehashing.
* The caller is responsible for calling rehashIfNeeded.