Skip to content

Commit 167525d

Browse files
Benedikts suggestions
1 parent c143ae2 commit 167525d

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

Doc/library/heapq.rst

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

8484

85+
For max heaps, the reverse of a heap, the following functions are provided:
86+
87+
8588
.. function:: heapify_max(x)
8689

87-
Transform list *x* into a heap, in-place, in linear time.
90+
Transform list *x* into a max heap, in-place, in linear time.
8891

8992
.. versionadded:: next
9093

9194

9295
.. function:: heappush_max(heap, item)
9396

94-
Push the value *item* onto the *heap*, maintaining the heap invariant.
97+
Push the value *item* onto the max *heap*, maintaining the heap invariant.
9598

9699
.. versionadded:: next
97100

101+
98102
.. function:: heappop_max(heap)
99103

100-
Pop and return the largest item from the *heap*, maintaining the heap
101-
invariant. If the heap is empty, :exc:`IndexError` is raised. To access the
104+
Pop and return the largest item from the max *heap*, maintaining the heap
105+
invariant. If the max heap is empty, :exc:`IndexError` is raised. To access the
102106
largest item without popping it, use ``heap[0]``.
103107

104108
.. versionadded:: next
105109

106110

107111
.. function:: heappushpop_max(heap, item)
108112

109-
Push *item* on the heap, then pop and return the largest item from the
113+
Push *item* on the max heap, then pop and return the largest item from the max
110114
*heap*. The combined action runs more efficiently than :func:`heappush_max`
111115
followed by a separate call to :func:`heappop_max`.
112116

@@ -115,17 +119,17 @@ The following functions are provided:
115119

116120
.. function:: heapreplace_max(heap, item)
117121

118-
Pop and return the largest item from the *heap*, and also push the new *item*.
119-
The heap size doesn't change. If the heap is empty, :exc:`IndexError` is raised.
122+
Pop and return the largest item from the max *heap*, and also push the new *item*.
123+
The max heap size doesn't change. If the max heap is empty, :exc:`IndexError` is raised.
120124

121-
This one step operation is more efficient than a :func:`heappop` followed by
122-
:func:`heappush` and can be more appropriate when using a fixed-size heap.
125+
This one step operation is more efficient than a :func:`heappop_max` followed by
126+
:func:`heappush_max` and can be more appropriate when using a fixed-size heap.
123127
The pop/push combination always returns an element from the heap and replaces
124128
it with *item*.
125129

126130
The value returned may be larger than the *item* added. If that isn't
127-
desired, consider using :func:`heappushpop` instead. Its push/pop
128-
combination returns the smaller of the two values, leaving the larger value
131+
desired, consider using :func:`heappushpop_max` instead. Its push/pop
132+
combination returns the larger of the two values, leaving the smaller value
129133
on the heap.
130134

131135
.. versionadded:: next

Lib/heapq.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,11 @@ def heapify_max(x):
214214
_siftup_max(x, i)
215215

216216
# 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()
217+
_heappop_max = heappop_max
218+
_heapreplace_max = heapreplace_max
219+
_heappush_max = _heappush_max
220+
_heappushpop_max = _heappushpop_max
221+
_heapify_max = _heapify_max
227222

228223

229224
# 'heap' is a heap at all indices >= startpos, except possibly for pos. pos

0 commit comments

Comments
 (0)