def __replace_key(self, item):
        """replace(item): pop and return the smallest item from the heap, and also
        push the new item. The heap size doesn't change. If the heap is empty,
        IndexError is raised. 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 routine unless written as part of a conditional replacement:
            if item > heap[0]:
                item = heapreplace(heap, item)
        """
        return heapreplace(self._heap, (self._key(item), self._itemid, item) )[2]
        self._itemid += 1
replace(item): pop and return the smallest item from the heap, and also
        push the new item. The heap size doesn't change. If the heap is empty,
        IndexError is raised. 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 routine unless written as part of a conditional replacement:
            if item > heap[0]:
                item = heapreplace(heap, item)
        
recipes/Python/502295_Heap_a_heapq_wrapper_class/recipe-502295.py