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-889] Collection algorithms that return indices of minimum and maximum elements #43501

Open
gribozavr opened this issue Mar 6, 2016 · 4 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-889
Radar rdar://problem/24999612
Original Reporter @gribozavr
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, StarterBug
Assignee valeriyvan (JIRA)
Priority Medium

md5: 323a62523ad9d65ac164670698a6c6ee

relates to:

  • SR-890 Sequence.minmax() and Collection.minmaxIndices()

Issue Description:

Some collections naturally maintain sorted order and can implement `minElement()` and `maxElement()` in O(1). But these APIs only return elements themselves. It is sometimes useful to get indices instead (e.g., if you want to mutate the element in the collection).

@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)

#32784

@swift-ci
Copy link
Collaborator

Comment by Daryle Walker (JIRA)

The code given in the pull request by valeriyvan (JIRA User) may not be needed. If you need the index of a minimum or maximum element (or both), you can run the direct extreme-finding method on the indices, but replace the element-level ordering predicate with an index-level ordering predicate that applies one layer of dereference then applies the original predicate on the mapping.

But that code won't help with the original request anyway. It implies adding new customization points to Collection, a pair for the extreme values and a pair for their indices. (Technically, you can get away with just the index-returning versions.) Collections whose structure don't track the extrema need linear-time default implementations.

(The original request is also problematic in that its assumed customization points are locked to <; you need a linear search for any other ordering. And what would be the policy for collections with elements that don't conform to Comparable?)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added StarterProposal and removed good first issue Good for newcomers labels Jul 6, 2022
@AnthonyLatsis AnthonyLatsis added good first issue Good for newcomers swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal feature A feature request or implementation 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

4 participants