Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-890] Sequence.minmax() and Collection.minmaxIndices() #43502

Open
gribozavr opened this issue Mar 6, 2016 · 7 comments
Open

[SR-890] Sequence.minmax() and Collection.minmaxIndices() #43502

gribozavr opened this issue Mar 6, 2016 · 7 comments
Labels
feature A feature request or implementation good first issue Good for newcomers improvement standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@gribozavr
Copy link
Collaborator

Previous ID SR-890
Radar rdar://problem/24999629
Original Reporter @gribozavr
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, StarterBug, StarterProposal
Assignee valeriyvan (JIRA)
Priority Medium

md5: f41321e080dfbdb86a60570a126cdad9

relates to:

  • SR-889 Collection algorithms that return indices of minimum and maximum elements

Issue Description:

It is sometimes useful to find both minimum and maximum elements at the same time. Currently, the library provides separate `min()` and `max()` methods for this. Running both methods requires 2n comparisons.

It is possible to implement a combined operation, `minmax()`, that would only require 1.5n comparisons.

Just like with min() and max(), we need both operations that return elements, and operations that return indices.

The idea behind the algorithm is to compare pairs of elements at positions 2i and 2i+1. This produces two sequences of elements:

(a) elements that are equal or greater than some element in the sequence,

(b) elements that compare less than some element in the sequence.

The minimum element is among elements in (b), the maximum element is among elements in (a).

minmax_element() in libc++ is a good example.

@natecook1000
Copy link
Member

Wouldn't minmax() be useful for sequences as well?

@gribozavr
Copy link
Collaborator Author

Absolutely! Retitled.

@swift-ci
Copy link
Collaborator

Comment by Félix Fischer (JIRA)

I could take this one. Is it still important?

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 2, 2019

Comment by Txai Wieser (JIRA)

Is this still relevant?

@belkadan
Copy link
Contributor

Resetting assignee on all Starter Bugs not modified since 2018.

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 8, 2020

Comment by Valeriy Van (JIRA)

I am on it.

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 9, 2020

Comment by Valeriy Van (JIRA)

Here's PR #32784

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal and removed StarterProposal labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation good first issue Good for newcomers improvement standard library Area: Standard library umbrella swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

5 participants