@@ -38,7 +38,7 @@ type Interface interface {
38
38
// Init establishes the heap invariants required by the other routines in this package.
39
39
// Init is idempotent with respect to the heap invariants
40
40
// and may be called whenever the heap invariants may have been invalidated.
41
- // Its complexity is O(n) where n = h.Len().
41
+ // The complexity is O(n) where n = h.Len().
42
42
func Init (h Interface ) {
43
43
// heapify
44
44
n := h .Len ()
@@ -47,28 +47,25 @@ func Init(h Interface) {
47
47
}
48
48
}
49
49
50
- // Push pushes the element x onto the heap. The complexity is
51
- // O(log(n)) where n = h.Len().
52
- //
50
+ // Push pushes the element x onto the heap.
51
+ // The complexity is O(log n) where n = h.Len().
53
52
func Push (h Interface , x interface {}) {
54
53
h .Push (x )
55
54
up (h , h .Len ()- 1 )
56
55
}
57
56
58
- // Pop removes the minimum element (according to Less) from the heap
59
- // and returns it. The complexity is O(log(n)) where n = h.Len().
60
- // It is equivalent to Remove(h, 0).
61
- //
57
+ // Pop removes and returns the minimum element (according to Less) from the heap.
58
+ // The complexity is O(log n) where n = h.Len().
59
+ // Pop is equivalent to Remove(h, 0).
62
60
func Pop (h Interface ) interface {} {
63
61
n := h .Len () - 1
64
62
h .Swap (0 , n )
65
63
down (h , 0 , n )
66
64
return h .Pop ()
67
65
}
68
66
69
- // Remove removes the element at index i from the heap and returns
70
- // the element. The complexity is O(log(n)) where n = h.Len().
71
- //
67
+ // Remove removes and returns the element at index i from the heap.
68
+ // The complexity is O(log n) where n = h.Len().
72
69
func Remove (h Interface , i int ) interface {} {
73
70
n := h .Len () - 1
74
71
if n != i {
@@ -83,7 +80,7 @@ func Remove(h Interface, i int) interface{} {
83
80
// Fix re-establishes the heap ordering after the element at index i has changed its value.
84
81
// Changing the value of the element at index i and then calling Fix is equivalent to,
85
82
// but less expensive than, calling Remove(h, i) followed by a Push of the new value.
86
- // The complexity is O(log(n) ) where n = h.Len().
83
+ // The complexity is O(log n ) where n = h.Len().
87
84
func Fix (h Interface , i int ) {
88
85
if ! down (h , i , h .Len ()) {
89
86
up (h , i )
0 commit comments