mirror of
https://github.com/golang/go
synced 2024-11-18 14:44:41 -07:00
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: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
716761b8b1
commit
f5352a7763
@ -107,7 +107,7 @@ func down(h Interface, i0, n int) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
j := j1 // left child
|
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
|
j = j2 // = 2*i + 2 // right child
|
||||||
}
|
}
|
||||||
if !h.Less(j, i) {
|
if !h.Less(j, i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user