Skip to content

Commit c143ae2

Browse files
Benedikts suggestions
1 parent beaf915 commit c143ae2

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

Doc/library/heapq.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,40 @@ The following functions are provided:
8282
on the heap.
8383

8484

85+
.. function:: heapify_max(x)
86+
87+
Transform list *x* into a heap, in-place, in linear time.
88+
89+
.. versionadded:: next
90+
91+
8592
.. function:: heappush_max(heap, item)
8693

8794
Push the value *item* onto the *heap*, maintaining the heap invariant.
8895

96+
.. versionadded:: next
8997

9098
.. function:: heappop_max(heap)
9199

92100
Pop and return the largest item from the *heap*, maintaining the heap
93101
invariant. If the heap is empty, :exc:`IndexError` is raised. To access the
94102
largest item without popping it, use ``heap[0]``.
95103

104+
.. versionadded:: next
105+
96106

97107
.. function:: heappushpop_max(heap, item)
98108

99109
Push *item* on the heap, then pop and return the largest item from the
100110
*heap*. The combined action runs more efficiently than :func:`heappush_max`
101111
followed by a separate call to :func:`heappop_max`.
102112

103-
104-
.. function:: heapify_max(x)
105-
106-
Transform list *x* into a max heap, in-place, in linear time.
113+
.. versionadded:: next
107114

108115

109-
.. function:: heapreplace(heap, item)
116+
.. function:: heapreplace_max(heap, item)
110117

111-
Pop and return the smallest item from the *heap*, and also push the new *item*.
118+
Pop and return the largest item from the *heap*, and also push the new *item*.
112119
The heap size doesn't change. If the heap is empty, :exc:`IndexError` is raised.
113120

114121
This one step operation is more efficient than a :func:`heappop` followed by
@@ -121,6 +128,8 @@ The following functions are provided:
121128
combination returns the smaller of the two values, leaving the larger value
122129
on the heap.
123130

131+
.. versionadded:: next
132+
124133

125134
The module also offers three general purpose functions based on heaps.
126135

Lib/heapq.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def heapify_max(x):
213213
for i in reversed(range(n//2)):
214214
_siftup_max(x, i)
215215

216+
# For backwards compadibility
217+
def _heappop_max(heap):
218+
return heappop_max(heap)
219+
def _heapreplace_max(heap, item):
220+
return heapreplace_max(heap, item)
221+
def _heappush_max(heap, item):
222+
return _heappush_max(heap, item)
223+
def _heappushpop_max(heap, item):
224+
return _heappushpop_max(heap, item)
225+
def _heapify_max(x):
226+
return _heapify_max()
227+
228+
216229
# 'heap' is a heap at all indices >= startpos, except possibly for pos. pos
217230
# is the index of a leaf with a possibly out-of-order value. Restore the
218231
# heap invariant.

0 commit comments

Comments
 (0)