gh-153357: Add object-oriented MinHeap and MaxHeap classes to heapq#153821
Draft
facundobatista wants to merge 4 commits into
Draft
gh-153357: Add object-oriented MinHeap and MaxHeap classes to heapq#153821facundobatista wants to merge 4 commits into
facundobatista wants to merge 4 commits into
Conversation
Documentation build overview
|
Member
|
I thought we decieed not to do it? the linked issue is also the wrong one |
facundobatista
marked this pull request as draft
July 17, 2026 14:32
Member
Author
|
@picnixz yes, sorry, I converted the PR to draft; I just proposed it so it serves as reference in the conversation, as some people is pushing for having this. Also fixed the issue number. Thanks! |
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
heapq.MinHeapandheapq.MaxHeap, an object-oriented interface to the existingheapqfunctions.Both classes wrap a list and expose the heap operations as methods, so you no longer have to pass the list around to the module-level functions:
The classes provide
push,pop,pushpop,replace,nsmallestandnlargest, plus__len__,__bool__and__repr__. MaxHeap behaves as a max-heap, using the*_maxvariants under the hood.The implementation is pure Python and delegates to the C-accelerated module functions, so there is no performance regression.
Includes documentation, a What's New entry and tests.