-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update research folder with new key sort
- Loading branch information
1 parent
706a7c2
commit 0fb10c2
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...Key Sorting/Control's Novel Buffered Key Sort for Strategy 1/Java/SortKeysWithBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// a novel, elegant, and incredibly efficient 1.5 sqrt n key sort, courtesy of Control | ||
// only works if a) median key is known and b) keys were permutated by "sortBlocks" | ||
// (keys < medianKey and >= medianKey are each in relative sorted order, resembling a final radix sort pass) | ||
private static <T> void sortKeys(T[] array, int firstKey, T medianKey, int keyCount, int buffer, Comparator<T> cmp) { | ||
int currKey = firstKey; | ||
int bufferSwaps = 0; | ||
|
||
while(currKey < firstKey + keyCount) { | ||
if(cmp.compare(array[currKey], medianKey) < 0) { | ||
if(bufferSwaps != 0) { | ||
swap(array, currKey, currKey - bufferSwaps); | ||
} | ||
} | ||
else { | ||
swap(array, currKey, buffer + bufferSwaps); | ||
bufferSwaps++; | ||
} | ||
currKey++; | ||
} | ||
|
||
swapBlocksBackwards(array, currKey - bufferSwaps, buffer, bufferSwaps); | ||
} |
2 changes: 2 additions & 0 deletions
2
Research/Key Sorting/Control's Novel Buffered Key Sort for Strategy 1/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# holy-grail-sort | ||
A faster implementation of in-place, stable, worst-case O(n log n) sorting |