]> Cypherpunks.ru repositories - gostls13.git/commitdiff
container/heap: optimization when selecting smaller child
authorltnwgl <ltnwgl@gmail.com>
Fri, 24 Mar 2017 03:55:22 +0000 (11:55 +0800)
committerRobert Griesemer <gri@golang.org>
Tue, 9 May 2017 03:38:37 +0000 (03:38 +0000)
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>
src/container/heap/heap.go

index 7110c513f0870fd86493fc1f32aee41bdffc7fdd..af05261c10a95d39849b575eb92fb083eac653cd 100644 (file)
@@ -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) {