Commit f5352a77 authored by ltnwgl's avatar ltnwgl Committed by Robert Griesemer

container/heap: optimization when selecting smaller child

In down(), if two children are equal, we can choose either one.
Inspired by https://codereview.appspot.com/6613064/

Change-Id: Iaad4ca5e2f5111bf3abb87f606584e7d274c620b
Reviewed-on: https://go-review.googlesource.com/38612
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 716761b8
......@@ -107,7 +107,7 @@ func down(h Interface, i0, n int) bool {
break
}
j := j1 // left child
if j2 := j1 + 1; j2 < n && !h.Less(j1, j2) {
if j2 := j1 + 1; j2 < n && h.Less(j2, j1) {
j = j2 // = 2*i + 2 // right child
}
if !h.Less(j, i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment