github.com/puellanivis/breton@v0.2.16/lib/sort/unsafe_go119.go (about) 1 //go:build !go1.20 2 // +build !go1.20 3 4 package sort 5 6 import ( 7 "math/bits" 8 "sort" 9 _ "unsafe" // this is to explicitly signal this file is unsafe. 10 ) 11 12 //go:linkname pdqsort sort.pdqsort 13 func pdqsort(data sort.Interface, a, b, maxDepth int) 14 15 // quickSort is just an aliased call into pdqsort, 16 // this means sort.go doesn’t need to be different between go1.19 and earlier. 17 func quickSort(data sort.Interface, a, b, maxDepth int) { 18 pdqsort(data, a, b, maxDepth/2) 19 } 20 21 // maxDepth returns a threashold at which quicksort should switch to heapsort. 22 // It returns 2 × ceil( log₂(n+1) ) 23 func maxDepth(n int) int { 24 if n <= 0 { 25 return 0 26 } 27 return 2 * bits.Len(uint(n)) 28 }