MCPcopy Create free account
hub / github.com/ActiveState/code / pushpop

Method pushpop

recipes/Python/440673_Safe_heap_queue_class/recipe-440673.py:36–40  ·  view source on GitHub ↗

Equivalent to "heap.push(); return heap.popmin()" but more efficient.

(self, item)

Source from the content-addressed store, hash-verified

34 return self._unwrap(heapq.heapreplace(self._lst, self._wrap(item)))
35
36 def pushpop(self, item):
37 'Equivalent to "heap.push(); return heap.popmin()" but more efficient.'
38 if self and self[0] < item:
39 return self.replace(item)
40 return item
41
42 def iterpop(self):
43 '''Return a destructive iterator over the heap's elements.

Callers

nothing calls this directly

Calls 1

replaceMethod · 0.95

Tested by

no test coverage detected