Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133530: Improve heapq documenation#133531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

StanFromIreland
Copy link
Contributor

@StanFromIrelandStanFromIreland commentedMay 6, 2025
edited
Loading

Removes a lot of unnecessary (and personal) parts. Also differentiate between heaps more, reference max-heap instead of a reverse list, and replace binary tree with a graphic I generated.

Some other thoughts:

Currently we use a pretty long sports analogy and use gender references, maybe a more neutral and technical description instead?

Add some headers for min/max heaps in the introduction for easier reference?


📚 Documentation preview 📚:https://cpython-previews--133531.org.readthedocs.build/en/133531/library/heapq.html

Copy link
Member

@AA-TurnerAA-Turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"Improve" here is in the eye of the beholder. Please be more conservative and cautious when proposing changes, and split up changes into different PRs. This contains 3 distinct changes: introducing the image, introducing min-/max-heap terminology, and removing quite a bit of prose.

I also don't know if Raymond has yet had a chance to review the change to introduce the max heap function, so this should potentially wait on that happening first.

A

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can this be an SVG?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is there a reason?

I used png since that is what hashlibs diagram uses.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

cpython/Doc/library$ find . -name '*.png'./pathlib-inheritance.png./tk_msg.png./tulip_coro.png./hashlib-blake2-tree.png./turtle-star.png./kde_example.pngcpython/Doc/library$ find . -name '*.svg'./pathlib-inheritance.svg

Comment on lines +309 to +312
Min-heaps are arrays for which ``a[k] <= a[2*k+1]`` and ``a[k] <= a[2*k+2]`` for
all*k*, counting elements from 0. For the sake of comparison, non-existing
elements are considered to be infinite. The interesting property of a heap is
that ``a[0]`` is always its smallest element.
that ``a[0]`` is always its smallest element. Max-heaps are the reverse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it's fine to default to "heap" being a "min-heap", and then introduce "max-heap" afterwards.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes that is what is done elsewhere.

I changed it here for clarity.

Comment on lines -349 to -350
heap. So, a heap is a good structure for implementing schedulers (this is what
I used for my MIDI sequencer :-).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's a shame to 'sterilise' things by removing lines like this. If you feel strongly, perhaps rework to keep the example but remove the perpendicular pronoun.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

See#62480 for arguments for removing personal notes. Do we need an even more specific example, IMO the general example is fine. Again, this is formal, technical documentation — not a blog post.

Comment on lines +351 to +352
Heaps are also very useful in big disk sorts.A
big sort implies producing "runs" (pre-sorted sequences, whose size is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think this needs to change

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is more formal? I thought that is what documentation should be…?

Comment on lines -373 to -389
heap completely vanishes, you switch heaps and start a new run. Clever and
quite effective!

In a word, heaps are useful memory structures to know. I use them in a few
applications, and I think it is good to keep a 'heap' module around. :-)

.. rubric:: Footnotes

.. [#] The disk balancing algorithms which are current, nowadays, are more annoying
than clever, and this is a consequence of the seeking capabilities of the disks.
On devices which cannot seek, like big tape drives, the story was quite
different, and one had to be very clever to ensure (far in advance) that each
tape movement will be the most effective possible (that is, will best
participate at "progressing" the merge). Some tapes were even able to read
backwards, and this was also used to avoid the rewinding time. Believe me, real
good tape sorts were quite spectacular to watch! From all times, sorting has
always been a Great Art! :-)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Likewise

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What is there to keep there? It is a largely a personal note and if I were to strip it to the core information it is irrelevant anyway.

Do you not want formal documentation?

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@StanFromIreland
Copy link
ContributorAuthor

I will split this for Adams convenience.

@StanFromIrelandStanFromIreland deleted the heapq-doc branchMay 7, 2025 16:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AA-TurnerAA-TurnerAA-Turner requested changes

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

Assignees

@rhettingerrhettinger

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@StanFromIreland@AA-Turner@rhettinger

[8]ページ先頭

©2009-2025 Movatter.jp