Skip to content

Extract heap helpers into a shared module - #1139

Merged
phimuemue merged 2 commits into
rust-itertools:masterfrom
GauravPawar101:heap
Nov 13, 2026
Merged

phimuemue merged 2 commits into
rust-itertools:masterfrom
GauravPawar101:heap

Conversation

@GauravPawar101

Copy link
Copy Markdown
Contributor

Closes #1108

kmerge_impl.rs and k_smallest.rs each had their own heap code. This moves
heapify and sift_down into src/heap.rs and uses them in both places.

PS

I kept the sift_down from kmerge_impl.rs since it was written to be
branchless. It's a min-heap, so k_smallest_general now passes a "greater
than" predicate to get the largest element on top, like before.

Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (6814180) to head (1a6e281).
⚠️ Report is 229 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1139      +/-   ##
==========================================
- Coverage   94.38%   93.71%   -0.68%     
==========================================
  Files          48       53       +5     
  Lines        6665     6458     -207     
==========================================
- Hits         6291     6052     -239     
- Misses        374      406      +32     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
@GauravPawar101

Copy link
Copy Markdown
Contributor Author

None of them is mine except fmt.

@phimuemue phimuemue left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you.

@phimuemue
phimuemue enabled auto-merge November 13, 2026 09:25
@phimuemue
phimuemue added this pull request to the merge queue Nov 13, 2026
Merged via the queue into rust-itertools:master with commit 8b4c6cb Nov 13, 2026
8 of 14 checks passed
@phimuemue

Copy link
Copy Markdown
Member

Thanks for this.

I always find it confusing to pass a greater_than into a function that expects a less_than (such as heapify or sift_down), and then commenting at the call site what you're doing.

It is a matter of taste, but what I usually do for these is this:

  • make the functions heapify and sift_down take a is_better instead of less_than.
  • annotate the callers this way heapify(/*is_better*/greater_than).

If you want, open a follow-up PR with these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify implementations of heaps

2 participants