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


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

Re: stream concat distinct indeterministic

Path csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: stream concat distinct indeterministic
Date Mon, 15 Feb 2016 21:58:17 -0000 (UTC)
Organization A noiseless patient Spider
Lines 43
Message-ID <n9thlp$4kk$1@dont-email.me> (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>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Mon, 15 Feb 2016 21:58:17 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="4756"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199Pm4HPYK5Bz8H/5RQiflRRE8vY21r098="
User-Agent Pan/0.140 (Chocolate Salty Balls; GIT 3663720 git://git.gnome.org/pan2)
Cancel-Lock sha1:rV8C7iVeamGzu5EOm8le3lnNjb0=
Xref csiph.com comp.lang.java.programmer:33831

Show key headers only | View raw


On Mon, 15 Feb 2016 16:13:14 -0500, Eric Sosman wrote:

>      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.
>
This doesn't surprise me because the Stream.distinct() method is only 
guaranteed to produce a stable result from an ordered input stream, which 
implies that the distinctness comparison is made between adjacent 
elements in the stream. So, I think there are two possible sources of 
instability:

1) Philipp hasn't said whether any of the streams being concatenated
   are ordered,

2) Even if the original streams are all ordered, simply concatenating 
   two or more streams will create a single unordered stream because
   concat() merely appends the content of Stream b to the content of
   Stream a

So, applying the sorted() to the output of concat() restores stability to 
distinct()'s operation no matter what the key sequence is in the original 
streams, which is why it solved Philipp's problem.

The only case calling sorted() adds no value is when the input streams 
are already ordered and each successive stream to be concatenated 
contains a key range whose lowest value is greater than or equal to the 
highest key value in the preceding stream.
 

-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

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