MCPcopy Index your code
hub / github.com/RustPython/RustPython / heapreplace

Function heapreplace

Lib/heapq.py:148–162  ·  view source on GitHub ↗

Pop and return the current smallest value, and add the new item. This is more efficient than heappop() followed by heappush(), and can be more appropriate when using a fixed-size heap. Note that the value returned may be larger than item! That constrains reasonable uses of this ro

(heap, item)

Source from the content-addressed store, hash-verified

146 return lastelt
147
148def heapreplace(heap, item):
149 """Pop and return the current smallest value, and add the new item.
150
151 This is more efficient than heappop() followed by heappush(), and can be
152 more appropriate when using a fixed-size heap. Note that the value
153 returned may be larger than item! That constrains reasonable uses of
154 this routine unless written as part of a conditional replacement:
155
156 if item > heap[0]:
157 item = heapreplace(heap, item)
158 """
159 returnitem = heap[0] # raises appropriate IndexError if heap is empty
160 heap[0] = item
161 _siftup(heap, 0)
162 return returnitem
163
164def heappushpop(heap, item):
165 """Fast version of a heappush followed by a heappop."""

Callers

nothing calls this directly

Calls 1

_siftupFunction · 0.85

Tested by

no test coverage detected