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

Add read-only elements getter to IdentifiedArray #12

Merged

Conversation

p4checo
Copy link
Contributor

@p4checo p4checo commented Jul 19, 2021

Until now there was no public API to efficiently return the elements from the underlying storage of IdentifiedArray as an [Element], requiring an O(n) map { $0 } via Collection to achieve this.

By taking advantage of the existing O(1) OrderedDictionary.values and OrderedDictionary.Values.elements getters, we can efficiently provide an O(1) read-only view of the elements in a more ergonomic way.

Changes

  • Add new read-only elements getter to IdentifiedArray.

Until now there was no public API to efficiently return the elements
from the underlying storage of `IdentifiedArray` as an `[Element]`,
requiring an `O(n)` `map { $0 }` via `Collection` to achieve this.

By taking advantage of the existing `O(1)` `OrderedDictionary.values`
and `OrderedDictionary.Values.elements` getters, we can efficiently
provide an `O(1)` read-only view of the elements in a more ergonomic
way.

## Changes

- Add new read-only `elements` getter to `IdentifiedArray`.
Copy link
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

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

Good call! Thanks for the suggestion 😄

@stephencelis stephencelis merged commit 0a83f49 into pointfreeco:main Jul 19, 2021
@p4checo p4checo deleted the add-read-only-elements-getter branch July 19, 2021 22:33
mgray88 pushed a commit to TakeoutCentral/swift-identified-collections that referenced this pull request Aug 26, 2021
Until now there was no public API to efficiently return the elements
from the underlying storage of `IdentifiedArray` as an `[Element]`,
requiring an `O(n)` `map { $0 }` via `Collection` to achieve this.

By taking advantage of the existing `O(1)` `OrderedDictionary.values`
and `OrderedDictionary.Values.elements` getters, we can efficiently
provide an `O(1)` read-only view of the elements in a more ergonomic
way.

## Changes

- Add new read-only `elements` getter to `IdentifiedArray`.
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.

2 participants