Commit 9d025bda authored by Russ Cox's avatar Russ Cox

container/heap: adjust wording in comments

Followup to CL 129779 but also some other minor tweaks.

Change-Id: Id71455d8a14f5e33f82c942c9e892da56c49d17c
Reviewed-on: https://go-review.googlesource.com/c/149257
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a48a666b
...@@ -38,7 +38,7 @@ type Interface interface { ...@@ -38,7 +38,7 @@ type Interface interface {
// Init establishes the heap invariants required by the other routines in this package. // Init establishes the heap invariants required by the other routines in this package.
// Init is idempotent with respect to the heap invariants // Init is idempotent with respect to the heap invariants
// and may be called whenever the heap invariants may have been invalidated. // and may be called whenever the heap invariants may have been invalidated.
// Its complexity is O(n) where n = h.Len(). // The complexity is O(n) where n = h.Len().
func Init(h Interface) { func Init(h Interface) {
// heapify // heapify
n := h.Len() n := h.Len()
...@@ -47,18 +47,16 @@ func Init(h Interface) { ...@@ -47,18 +47,16 @@ func Init(h Interface) {
} }
} }
// Push pushes the element x onto the heap. The complexity is // Push pushes the element x onto the heap.
// O(log(n)) where n = h.Len(). // The complexity is O(log n) where n = h.Len().
//
func Push(h Interface, x interface{}) { func Push(h Interface, x interface{}) {
h.Push(x) h.Push(x)
up(h, h.Len()-1) up(h, h.Len()-1)
} }
// Pop removes the minimum element (according to Less) from the heap // Pop removes and returns the minimum element (according to Less) from the heap.
// and returns it. The complexity is O(log(n)) where n = h.Len(). // The complexity is O(log n) where n = h.Len().
// It is equivalent to Remove(h, 0). // Pop is equivalent to Remove(h, 0).
//
func Pop(h Interface) interface{} { func Pop(h Interface) interface{} {
n := h.Len() - 1 n := h.Len() - 1
h.Swap(0, n) h.Swap(0, n)
...@@ -66,9 +64,8 @@ func Pop(h Interface) interface{} { ...@@ -66,9 +64,8 @@ func Pop(h Interface) interface{} {
return h.Pop() return h.Pop()
} }
// Remove removes the element at index i from the heap and returns // Remove removes and returns the element at index i from the heap.
// the element. The complexity is O(log(n)) where n = h.Len(). // The complexity is O(log n) where n = h.Len().
//
func Remove(h Interface, i int) interface{} { func Remove(h Interface, i int) interface{} {
n := h.Len() - 1 n := h.Len() - 1
if n != i { if n != i {
...@@ -83,7 +80,7 @@ func Remove(h Interface, i int) interface{} { ...@@ -83,7 +80,7 @@ func Remove(h Interface, i int) interface{} {
// Fix re-establishes the heap ordering after the element at index i has changed its value. // Fix re-establishes the heap ordering after the element at index i has changed its value.
// Changing the value of the element at index i and then calling Fix is equivalent to, // Changing the value of the element at index i and then calling Fix is equivalent to,
// but less expensive than, calling Remove(h, i) followed by a Push of the new value. // but less expensive than, calling Remove(h, i) followed by a Push of the new value.
// The complexity is O(log(n)) where n = h.Len(). // The complexity is O(log n) where n = h.Len().
func Fix(h Interface, i int) { func Fix(h Interface, i int) {
if !down(h, i, h.Len()) { if !down(h, i, h.Len()) {
up(h, i) up(h, i)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment