UnsafeKVExternalSorter uses UnsafeInMemorySorter to sort the records of BytesToBytesMap if it is given a map.
Currently we use the number of keys in BytesToBytesMap to determine if the array used for sort is enough or not. We has an assert that ensures the size of the array is enough: map.numKeys() <= map.getArray().size() / 2.
However, each record in the map takes two entries in the array, one is record pointer, another is key prefix. So the correct assert should be map.numKeys() * 2 <= map.getArray().size() / 2.