Pop the smallest item off the heap, maintaining the heap invariant.
(heap)
| 136 | _siftdown(heap, 0, len(heap)-1) |
| 137 | |
| 138 | def heappop(heap): |
| 139 | """Pop the smallest item off the heap, maintaining the heap invariant.""" |
| 140 | lastelt = heap.pop() # raises appropriate IndexError if heap is empty |
| 141 | if heap: |
| 142 | returnitem = heap[0] |
| 143 | heap[0] = lastelt |
| 144 | _siftup(heap, 0) |
| 145 | return returnitem |
| 146 | return lastelt |
| 147 | |
| 148 | def heapreplace(heap, item): |
| 149 | """Pop and return the current smallest value, and add the new item. |