aboutsummaryrefslogtreecommitdiff
path: root/src/sort
diff options
context:
space:
mode:
Diffstat (limited to 'src/sort')
-rw-r--r--src/sort/search_test.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/sort/search_test.go b/src/sort/search_test.go
index 49813eaecb..b6ab900abe 100644
--- a/src/sort/search_test.go
+++ b/src/sort/search_test.go
@@ -5,6 +5,7 @@
package sort_test
import (
+ "math/bits"
"runtime"
. "sort"
stringspkg "strings"
@@ -135,13 +136,10 @@ func TestFind(t *testing.T) {
// log2 computes the binary logarithm of x, rounded up to the next integer.
// (log2(0) == 0, log2(1) == 0, log2(2) == 1, log2(3) == 2, etc.)
func log2(x int) int {
- n := 0
- for p := 1; p < x; p += p {
- // p == 2**n
- n++
+ if x < 1 {
+ return 0
}
- // p/2 < x <= p == 2**n
- return n
+ return bits.Len(uint(x - 1))
}
func TestSearchEfficiency(t *testing.T) {