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

Implement ExactSizeIterator for (Circular)TupleWindows #752

Merged

Conversation

Philippe-Cholet
Copy link
Member

@Philippe-Cholet Philippe-Cholet commented Sep 18, 2023

Closes #660
Implement ExactSizeIterator without any additional cost:

  • For CircularTupleWindows by flattenning the struct Take<I> { iter: I, n: usize } from iter: Take<TupleWindows<Cycle<I>, T>> into iter: TupleWindows<Cycle<I>, T>, len: usize.
    It has the same length as the input (exact size) iterator.
    Implement FusedIterator as well.
  • For TupleWindows if the input iterator is exact sized. Relies on the fact that T::num_items() - 1 items are collected at definition.

Add a field to know the length of the iterator.
Implemented under the same conditions `Iterator` is implemented.
It implements a method `len` which rely on an exact size hint.
Implemented under the same conditions `Iterator` and `ExactSizeIterator` are implemented.
src/tuple_impl.rs Show resolved Hide resolved
`len` was a duplicate since `Take` also had it.
`CircularTupleWindows::next` is how is implemented `Take::next`.
@Philippe-Cholet Philippe-Cholet changed the title Implement ExactSizeIterator for CircularTupleWindows Implement ExactSizeIterator for (Circular)TupleWindows Sep 19, 2023
src/tuple_impl.rs Show resolved Hide resolved
@jswrenn jswrenn added this pull request to the merge queue Sep 19, 2023
Merged via the queue into rust-itertools:master with commit 882581f Sep 19, 2023
10 checks passed
@Philippe-Cholet Philippe-Cholet deleted the circular-windows-exact-size branch September 19, 2023 13:36
@jswrenn jswrenn added this to the next milestone Sep 19, 2023
@jswrenn jswrenn mentioned this pull request Nov 14, 2023
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.

Implement ExactSizeIterator for CircularTupleWindows
2 participants