Fix JIRA-983 and support exteranl sort for sortByKey

Change class ExternalAppendOnlyMap and make it support customized comparator function(not only sorted by hashCode).
minor: I would probably add a method in `StreamBuffer` called `minPair`, so you can just do `mergeHeap.head.minPair`. Then I would declare a val a few lines above

```
val minPair = minPairs.remove(0)
var (minKey, minCombiner) = minPair
...
```
so this line fits under 100 char and is more readable.