aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/container/heap/heap.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/container/heap/heap.go')
-rw-r--r--libgo/go/container/heap/heap.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/libgo/go/container/heap/heap.go b/libgo/go/container/heap/heap.go
index 7110c513f08..b2c64276c82 100644
--- a/libgo/go/container/heap/heap.go
+++ b/libgo/go/container/heap/heap.go
@@ -72,8 +72,9 @@ func Remove(h Interface, i int) interface{} {
n := h.Len() - 1
if n != i {
h.Swap(i, n)
- down(h, i, n)
- up(h, i)
+ if !down(h, i, n) {
+ up(h, i)
+ }
}
return h.Pop()
}
@@ -107,7 +108,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) {