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

Make Take and Skip iterators DoubleEnded when constructed from ExactSize #12785

Closed
wants to merge 1 commit into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Mar 9, 2014

Fixes #12784

@ghost
Copy link
Author

ghost commented Mar 9, 2014

Skip could also be specialized for A: RandomAccessIterators + ExactSize to make it more efficient in that case.

@bill-myers
Copy link
Contributor

Might not be a good idea to merge this, because it has unintuitively slow performance.

Specifically, you might expect linked_list.iter().take(K).rev() to take O(k) operations, but instead it takes O(n) where n is the size of a linked list (and in fact, the current implementation will be slow for all iterators).

Those wanting to do this can use iter().rev().skip(N - K) instead, which makes the performance impact obvious.

Or they can more sensibly decide to collect the first K elements in a vector, and then reverse that, which is the time-efficient way of doing it.

@ghost
Copy link
Author

ghost commented Mar 9, 2014

Agreed.

It'd be possible to only implement these for A: ExactSize + RandomAccessIterator and then take(k).rev() could indeed be O(k). As would skip(n).take(k), which currently is O(n + k).

@alexcrichton
Copy link
Member

Travis has some failures which should get addressed before merging

@ghost ghost closed this Mar 11, 2014
@ghost ghost deleted the iter-take-skip-double-ended-exact-size branch June 5, 2014 16:41
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
…t-generics, r=Veykril

fix: un-inline `ConstScalarOrPath::from_expr_opt`

Sorry, but I missed these from rust-lang#12778 `@flodiebold`
This pull request was closed.
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.

RFC: Make Take and Skip iterators DoubleEndedIterators when built from ExactSize iterators
2 participants