Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33835

Re: stream concat distinct indeterministic

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: stream concat distinct indeterministic
Date 2016-02-15 21:45 -0500
Organization Aioe.org NNTP Server
Message-ID <n9u2fs$blv$1@gioia.aioe.org> (permalink)
References <6e75cf37-61c1-4ab8-af9b-851fc280244d@googlegroups.com> <n9suej$j9v$1@gioia.aioe.org> <e3b09b77-efe8-49e1-8586-18685bade8f8@googlegroups.com> <n9ters$usi$1@dont-email.me>

Show all headers | View raw


On 2/15/2016 4:13 PM, Eric Sosman wrote:
> On 2/15/2016 3:54 PM, Philipp Kraus wrote:
>> Am Montag, 15. Februar 2016 17:30:23 UTC+1 schrieb Arne Vajhøj:
>>> On 2/15/2016 11:08 AM, Philipp Kraus wrote:
>>>> I run Stream.concat to concat two streams. These two streams are
>>>> "stream" and use a flatMap call. After the concat I run distinct() to
>>>> create an unique stream of elements, but I get an indeterministic
>>>> behaviour of my concated stream, so my question is how can I create a
>>>> concated and distinct stream?
>>>
>>> Docs for distinct says:
>>>
>>> "For ordered streams, the selection of distinct elements is stable (for
>>> duplicated elements, the element appearing first in the encounter order
>>> is preserved.) For unordered streams, no stability guarantees are made."
>>>
>>> so I would guess that you would need to do .sorted().distinct() instead
>>> of just .distinct().
>>
>> Thanks, this seems to be working, I have added a compareTo (overload)
>> and run sorted() before distinct().
>
>      Let's review for a moment.  From bits and pieces of several posts,
> it seems you began with
>
>      Stream.concat(str1, str2).distinct().count();
>
> ... and reported that the same str1/2 produced different counts in
> different runs.  Now you've changed to
>
>      Stream.concat(str1, str2).sorted().distinct().count();
>
> ... which shouldn't ("shouldn't") change anything, yet you now report
> that everything appears to be working.
>
>      Except, of course, that there's no obvious reason why the original
> pipeline would misbehave, and no obvious reason why sorted() should make
> any difference (there are exactly as many elements in ACDB as in ABCD).
> So I *strongly* encourage you not to let the matter rest, but to look
> deeper and see what's really going on.
>
>      You may have uncovered a serious bug in the streams framework --
> or you may have made a slip-up elsewhere.  The former is possible, but
> to me the latter seems far more likely.

The post I replied to did not talk about different count but about
"indeterministic behaviour".

.sorted() should not impact .count() at all, but I thought it may
help on .distinct() and "indeterministic behaviour".

Arne

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

stream concat distinct indeterministic Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-02-15 08:08 -0800
  Re: stream concat distinct indeterministic Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 11:30 -0500
    Re: stream concat distinct indeterministic Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-02-15 12:54 -0800
      Re: stream concat distinct indeterministic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 16:13 -0500
        Re: stream concat distinct indeterministic Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-15 21:58 +0000
          Re: stream concat distinct indeterministic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 17:45 -0500
            Re: stream concat distinct indeterministic Martin Gregorie <martin@address-in-sig.invalid> - 2016-02-15 23:29 +0000
              Re: stream concat distinct indeterministic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-16 07:47 -0500
        Re: stream concat distinct indeterministic Arne Vajhøj <arne@vajhoej.dk> - 2016-02-15 21:45 -0500
  Re: stream concat distinct indeterministic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 11:38 -0500
    Re: stream concat distinct indeterministic Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-02-15 09:05 -0800
      Re: stream concat distinct indeterministic Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-15 14:08 -0500
      Re: stream concat distinct indeterministic Andreas Leitgeb <avl@logic.at> - 2016-02-16 18:40 +0000

csiph-web