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

Feature request: Implement DoubleEndedIterator for MergeBy if the source iterators implement DoubleEndedIterator #749

Closed
frankdavid opened this issue Sep 6, 2023 · 1 comment

Comments

@frankdavid
Copy link

The current implementation of next() makes use of Peekable. Both iterators get peeked and a comparator is used to decide which element is picked / which iterator gets advanced.

The main difficulty when implementing next_back() for DoubleEndedIterator would be that Peekable only allows peeking the front and not the back. The MergeBy struct would either manually have to store the front and back peeked values or use a data structure like DoubleEndedPeekable.

If we could peek the back, the rest of the implementation would be straightforward, only the comparator's return value would need to be negated when iterating from the back.

@Philippe-Cholet
Copy link
Member

Philippe-Cholet commented Sep 7, 2023

There is some work of mine in #736 that would change the internal behavior from peekable to put_back but that does not change the fact it only looks at the front and not the back. I guess it would need some DoubleEndedPutBack (or store both fronts).

EDIT: I highly doubt it will be implemented, too many implications to the code for what seems to have little use case. What about it1.rev().merge_by(it2.rev(), func)?
I guess a DoubleEndedPeekable structure would be an intermediary feature.

@Philippe-Cholet Philippe-Cholet closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants