-
Notifications
You must be signed in to change notification settings - Fork 252
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
New method skipSorted(n) in StreamEx #61
Comments
Thank you for proposal. It surely needs some evaluation before it can be integrated into StreamEx. First thing to note is that since StreamEx 0.5.4 there will be
Now you can use, for example:
So even if some operation is absent in So back to your operations. First, Note that such Now It potentially can be properly parallelized, which is good. Your implementation does not care about this, but it's possible to write correct parallel version which will use I still want to take a look on Also it would be nice to see some use cases where such operations would be useful. |
Both of these methods have to do at least 1 pass at the entire stream before it can know which elements to skip or limit. So, neither of these methods can process an infinite stream. |
@nathanila no.
|
Oh, I miss read the requirements. I thought |
Requested here by @AgnetaWalterscheidt:
I would like to implement a new method in
StreamEx
(orAbstractStreamEx
):The method skips the first n elements of the stream as if the stream was sorted using the comparator but without actually sorting the whole stream.
The method is similar to
MoreCollectors.greatest(Comparator<? super T>, int)
butFor symmetry I would like to implement a second method:
which is the counterpart to the first method because it limits the stream by returning only the first n elements of the stream (after "sorting" it like in the first method). This method obviously does not return a stream with an infinite number of elements (the stream will have n or less elements) but I think it would be confusing for the users of your library to look for the second method somewhere else.
I have already implemented a method
skipSorted()
that takes and returns anIterator
. You find the code below including a small test method (currently called from a main method).I have also implemented (not included but I can send you the code if you are interested) a method
skipSorted()
using aPriorityQueue
for sorting, and one using aTreeSet
. The quickselect implementation is on average about factor 3 faster than the others.The
StreamEx
method could be implemented as a small wrapper around these methods.Please tell me if you would like me to implement this!
Cheers
Agneta
Code:
The text was updated successfully, but these errors were encountered: