aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala')
-rw-r--r--core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala15
1 files changed, 5 insertions, 10 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala b/core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala
index 1a6f1c2b55..290282c9c2 100644
--- a/core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala
+++ b/core/src/main/scala/org/apache/spark/util/collection/AppendOnlyMap.scala
@@ -254,26 +254,21 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64)
* Return an iterator of the map in sorted order. This provides a way to sort the map without
* using additional memory, at the expense of destroying the validity of the map.
*/
- def destructiveSortedIterator(cmp: Comparator[(K, V)]): Iterator[(K, V)] = {
+ def destructiveSortedIterator(keyComparator: Comparator[K]): Iterator[(K, V)] = {
destroyed = true
// Pack KV pairs into the front of the underlying array
var keyIndex, newIndex = 0
while (keyIndex < capacity) {
if (data(2 * keyIndex) != null) {
- data(newIndex) = (data(2 * keyIndex), data(2 * keyIndex + 1))
+ data(2 * newIndex) = data(2 * keyIndex)
+ data(2 * newIndex + 1) = data(2 * keyIndex + 1)
newIndex += 1
}
keyIndex += 1
}
assert(curSize == newIndex + (if (haveNullValue) 1 else 0))
- // Sort by the given ordering
- val rawOrdering = new Comparator[AnyRef] {
- def compare(x: AnyRef, y: AnyRef): Int = {
- cmp.compare(x.asInstanceOf[(K, V)], y.asInstanceOf[(K, V)])
- }
- }
- Arrays.sort(data, 0, newIndex, rawOrdering)
+ new Sorter(new KVArraySortDataFormat[K, AnyRef]).sort(data, 0, newIndex, keyComparator)
new Iterator[(K, V)] {
var i = 0
@@ -284,7 +279,7 @@ class AppendOnlyMap[K, V](initialCapacity: Int = 64)
nullValueReady = false
(null.asInstanceOf[K], nullValue)
} else {
- val item = data(i).asInstanceOf[(K, V)]
+ val item = (data(2 * i).asInstanceOf[K], data(2 * i + 1).asInstanceOf[V])
i += 1
item
}