summaryrefslogtreecommitdiff
path: root/libgo/go/container
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/container')
-rw-r--r--libgo/go/container/heap/example_test.go42
1 files changed, 21 insertions, 21 deletions
diff --git a/libgo/go/container/heap/example_test.go b/libgo/go/container/heap/example_test.go
index c3b8d94cb2a..2050bc83591 100644
--- a/libgo/go/container/heap/example_test.go
+++ b/libgo/go/container/heap/example_test.go
@@ -57,11 +57,26 @@ func (pq *PriorityQueue) Pop() interface{} {
return item
}
-// 99:seven 88:five 77:zero 66:nine 55:three 44:two 33:six 22:one 11:four 00:eight
-func ExampleInterface() {
- // The full code of this example, including the methods that implement
- // heap.Interface, is in the file src/pkg/container/heap/example_test.go.
+// update is not used by the example but shows how to take the top item from
+// the queue, update its priority and value, and put it back.
+func (pq *PriorityQueue) update(value string, priority int) {
+ item := heap.Pop(pq).(*Item)
+ item.value = value
+ item.priority = priority
+ heap.Push(pq, item)
+}
+// changePriority is not used by the example but shows how to change the
+// priority of an arbitrary item.
+func (pq *PriorityQueue) changePriority(item *Item, priority int) {
+ heap.Remove(pq, item.index)
+ item.priority = priority
+ heap.Push(pq, item)
+}
+
+// This example pushes 10 items into a PriorityQueue and takes them out in
+// order of priority.
+func Example() {
const nItem = 10
// Random priorities for the items (a permutation of 0..9, times 11)).
priorities := [nItem]int{
@@ -85,21 +100,6 @@ func ExampleInterface() {
item := heap.Pop(&pq).(*Item)
fmt.Printf("%.2d:%s ", item.priority, item.value)
}
-}
-
-// update is not used by the example but shows how to take the top item from the queue,
-// update its priority and value, and put it back.
-func (pq *PriorityQueue) update(value string, priority int) {
- item := heap.Pop(pq).(*Item)
- item.value = value
- item.priority = priority
- heap.Push(pq, item)
-}
-
-// changePriority is not used by the example but shows how to change the priority of an arbitrary
-// item.
-func (pq *PriorityQueue) changePriority(item *Item, priority int) {
- heap.Remove(pq, item.index)
- item.priority = priority
- heap.Push(pq, item)
+ // Output:
+ // 99:seven 88:five 77:zero 66:nine 55:three 44:two 33:six 22:one 11:four 00:eight
}