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