FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
container/heap: Simplify the example.

Using append simplifies the code and makes it work if
the initial capacity of the slice is smaller than the
number of items pushed.

Please review this at https://codereview.appspot.com/6869060/

Affected files:
M src/pkg/container/heap/example_test.go


Index: src/pkg/container/heap/example_test.go
===================================================================
--- a/src/pkg/container/heap/example_test.go
+++ b/src/pkg/container/heap/example_test.go
@@ -37,15 +37,10 @@ func (pq PriorityQueue) Swap(i, j int) {
func (pq *PriorityQueue) Push(x interface{}) {
// Push and Pop use pointer receivers because they modify the slice's
length,
// not just its contents.
- // To simplify indexing expressions in these methods, we save a copy of
the
- // slice object. We could instead write (*pq)[i].
- a := *pq
- n := len(a)
- a = a[0 : n+1]
+ n := len(*pq)
item := x.(*Item)
item.index = n
- a[n] = item
- *pq = a
+ *pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 4, '12 at 8:59p
activeDec 4, '12 at 10:11p
posts3
users2
websitegolang.org

2 users in discussion

Gri: 2 posts Schulze: 1 post

People

Translate

site design / logo © 2022 Grokbase