gh-112498: Allow removal/update of an object at an arbitary position in a a heap#112497
Open
kristjanvalur wants to merge 7 commits intopython:mainfrom
Open
gh-112498: Allow removal/update of an object at an arbitary position in a a heap#112497kristjanvalur wants to merge 7 commits intopython:mainfrom
kristjanvalur wants to merge 7 commits intopython:mainfrom
Conversation
Contributor
Author
|
Maybe worth mentioning as "future music", that it would be easy to add an optional, keyword-only, argument "map" to all the methods, to maintain a |
This was referenced Nov 30, 2023
|
This PR is stale because it has been open for 30 days with no activity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/