Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(80)

Unified Diff: src/pkg/container/heap/example_test.go

Issue 6869060: code review 6869060: container/heap: Simplify the example. (Closed)
Patch Set: diff -r daabe25e67fe https://code.google.com/p/go Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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{} {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b