Re: Stream API: Fuse sorted().limit(n) into single operation

2016-03-07 Thread Peter Levart
Hi Tagir, On 03/07/2016 04:30 PM, Tagir F. Valeev wrote: Hello! Thank you for your comments! PL> - in Limiter.put: Nice catch! A good example when series of minor code refactorings lead to something strange. Webrev is updated in-place: http://cr.openjdk.java.net/~tvaleev/patches/sortedLimit/w

Re: Stream API: Fuse sorted().limit(n) into single operation

2016-03-07 Thread Tagir F. Valeev
Hello! Thank you for your comments! PL> - in Limiter.put: Nice catch! A good example when series of minor code refactorings lead to something strange. Webrev is updated in-place: http://cr.openjdk.java.net/~tvaleev/patches/sortedLimit/webrev/ PL> Also, what do you think of the following merging

Re: Stream API: Fuse sorted().limit(n) into single operation

2016-03-06 Thread Peter Levart
Hi Tagir, Nice work. I looked at the implementation and have two comments: - in Limiter.put: 127 final boolean put(T t) { 128 int l = limit; 129 T[] d = data; 130 if (l == 1) { 131 // limit == 1 is the special case: exactly one le

Re: Stream API: Fuse sorted().limit(n) into single operation

2016-03-05 Thread Tagir F. Valeev
Hello! LW> Worth noting: Guava uses a similar implementation for LW> Ordering.leastOf, but instead of sorting the array when it's LW> filled, does a quickselect pass to do it in O(k) time instead of O(k log k).  Thank you for mentioning Guava. Unfortunately quickselect is not stable, while sorte