Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ class ExternalAppendOnlyMap[K, V, C](
}

override def compareTo(other: StreamBuffer): Int = {
// minus sign because mutable.PriorityQueue dequeues the max, not the min
-minKeyHash.compareTo(other.minKeyHash)
// descending order because mutable.PriorityQueue dequeues the max, not the min
if (other.minKeyHash < minKeyHash) -1 else if (other.minKeyHash == minKeyHash) 0 else 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use Integer.compare instead of writing these manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also write our own Utils.compare, though this is only used in 2 places so I think it's fine to just write it out directly. Also this is a super hot code path so maybe it's better to just avoid function calls altogether (maybe, maybe not).

}
}
}
Expand Down Expand Up @@ -422,7 +422,9 @@ class ExternalAppendOnlyMap[K, V, C](
private[spark] object ExternalAppendOnlyMap {
private class KCComparator[K, C] extends Comparator[(K, C)] {
def compare(kc1: (K, C), kc2: (K, C)): Int = {
kc1._1.hashCode().compareTo(kc2._1.hashCode())
val hash1 = kc1._1.hashCode()
val hash2 = kc2._1.hashCode()
if (hash1 < hash2) -1 else if (hash1 == hash2) 0 else 1
}
}
}