From f5352a7763c8f96f7f092990d64339eae0623263 Mon Sep 17 00:00:00 2001 From: ltnwgl Date: Fri, 24 Mar 2017 11:55:22 +0800 Subject: [PATCH] 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 Reviewed-by: Robert Griesemer --- src/container/heap/heap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/container/heap/heap.go b/src/container/heap/heap.go index 7110c513f0..af05261c10 100644 --- a/src/container/heap/heap.go +++ b/src/container/heap/heap.go @@ -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) { -- 2.48.1