-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a055cd5
commit 3499d1d
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
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,25 @@ | ||
package sort | ||
|
||
import ( | ||
"math/bits" | ||
"sort" | ||
_ "unsafe" // this is to explicitly signal this file is unsafe. | ||
) | ||
|
||
//go:linkname pdqsort sort.pdqsort | ||
func pdqsort(data sort.Interface, a, b, maxDepth int) | ||
|
||
// quickSort is just an aliased call into pdqsort, | ||
// this means sort.go doesn’t need to be different between go1.19 and earlier. | ||
func quickSort(data sort.Interface, a, b, maxDepth int) { | ||
pdqsort(data, a, b, maxDepth/2) | ||
} | ||
|
||
// maxDepth returns a threashold at which quicksort should switch to heapsort. | ||
// It returns 2 × ceil( log₂(n+1) ) | ||
func maxDepth(n int) int { | ||
if n <= 0 { | ||
return 0 | ||
} | ||
return 2 * bits.Len(uint(n)) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !go1.19 | ||
// +build !go1.19 | ||
|
||
package sort | ||
|
||
import ( | ||
|