Repository navigation
Compute each key only once in position_{min,max,minmax}_by_key - #1136
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1136 +/- ##
==========================================
- Coverage 94.38% 93.72% -0.67%
==========================================
Files 48 52 +4
Lines 6665 6484 -181
==========================================
- Hits 6291 6077 -214
- Misses 374 407 +33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Hi @ronnodas, thanks, this looks reasonable. |
phimuemue
enabled auto-merge
October 21, 2026 14:05
Member
|
And I guess this also opens the door for your idea about making the function |
phimuemue
approved these changes
Oct 21, 2026
Contributor
Author
Yes, I can file a PR for that once this one is merged. |
Merged
via the queue into
rust-itertools:master
with commit Oct 21, 2026
7c1bbef
8 of 14 checks passed
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.
Right now the methods
position_{min,max,minmax}_by_keyevaluate the user provided key function each time each item is compared with another, which seems unnecessary, especially in case computing the key is expensive. Note that in any correct implementation, every item must be compared at least once, so each key must be computed at least once.This does theoretically change the behavior since the key function is allowed to be stateful, in particular if it is non-deterministic.