Skip to content

Commit

Permalink
Make initialSize configurable in UnsafeSorter
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed May 1, 2015
1 parent abf7bfe commit 57a4ea0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static abstract class PrefixComparator {
* Within this buffer, position {@code 2 * i} holds a pointer pointer to the record at
* index {@code i}, while position {@code 2 * i + 1} in the array holds an 8-byte key prefix.
*/
private long[] sortBuffer = new long[1024];
private long[] sortBuffer;

private int sortBufferInsertPosition = 0;

Expand All @@ -82,7 +82,10 @@ public UnsafeSorter(
final TaskMemoryManager memoryManager,
final RecordComparator recordComparator,
PrefixComputer prefixComputer,
final PrefixComparator prefixComparator) {
final PrefixComparator prefixComparator,
int initialSize) {
assert (initialSize > 0);
this.sortBuffer = new long[initialSize * 2];
this.memoryManager = memoryManager;
this.prefixComputer = prefixComputer;
this.sorter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public int compare(long prefix1, long prefix2) {
return (int) prefix1 - (int) prefix2;
}
};
final UnsafeSorter sorter =
new UnsafeSorter(memoryManager, recordComparator, prefixComputer, prefixComparator);
final UnsafeSorter sorter = new UnsafeSorter(memoryManager, recordComparator, prefixComputer,
prefixComparator, dataToSort.length);
// Given a page of records, insert those records into the sorter one-by-one:
position = dataPage.getBaseOffset();
for (int i = 0; i < dataToSort.length; i++) {
Expand Down

0 comments on commit 57a4ea0

Please sign in to comment.