The current computation loops indefinitely if n > 1<<30 (for 32-bit ints).
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/
5848067
// Sort sorts data.
// The algorithm used is not guaranteed to be a stable sort.
func Sort(data Interface) {
- // Switch to heapsort if depth of 2*ceil(lg(n)) is reached.
+ // Switch to heapsort if depth of 2*ceil(lg(n+1)) is reached.
n := data.Len()
maxDepth := 0
- for 1<<uint(maxDepth) < n {
+ for i := n; i > 0; i >>= 1 {
maxDepth++
}
maxDepth *= 2