gh-112498: Allow removal/update of an object at an arbitary position in a a heap by kristjanvalur · Pull Request #112497 · python/cpython (original) (raw)
Add a function, heapremove()
to remove an object at a known place in the heap, while maintaining the heap invariant.
A replacement object can be provided to place on the heap in stead of the removed object.
This function can also be used to restore the heap invariant after the value of an object on the heap has
changed.
I have selected the name heapremove()
for this functionality but am open to suggestions. heapmodify()
? It could also be split into two functions (e.g. heapdel and heapupdate), one for removing an item at an arbitrary place, and another for merely update the heap if there is a modification at a given index.
Some of the existing functions could also be augmented with optional arguments, although providing a default value for 'index' is not easy, particularly if we allow it to be negative, like normal list indices.
📚 Documentation preview 📚: https://cpython-previews--112497.org.readthedocs.build/