No,
It breaks on Fi (or Fum) in the inner loop before it gets the chance to output
Fi-Fum (or Fum-Fi) if Fi (respectively Fum) comes first in iteration order.
--
Have a nice day,
Timo
Sent from Mail for Windows 10
From: Dave Brosius
That would give you unwanted duplicates
Fi-Fum and Fum-Fi for instance
On 09/11/2016 08:58 PM, Tagir Valeev wrote:
Actually given the fact that we're iterating the Set (so the elements
are unique) and using the assumption that iteration of the same set is
stable, you can avoid numbering like
Actually given the fact that we're iterating the Set (so the elements are
unique) and using the assumption that iteration of the same set is stable,
you can avoid numbering like this:
for(String e1 : set) {
for(String e2 : set) {
if(e1 == e2) break;
System.out.println(e1+" <-> "+e2);
}
Hello, Peter!
I thought about numbering, but original Dave's code involved concurrent
set, so I presume that it's expected to be modified from other threads. In
this case my algorithm would output some legal pairs (probably reflecting
changes or not or reflecting only partially) while your algorit
I would say the algorithm is O(n), when you take n to be the number of
emitted pairs, wouldn't you ;-)
You wanted an algorithm that emits n*(n-1) / 2 distinct pairs of
elements from a set of n elements, didn't you?
Regards, Peter
On 09/11/2016 06:55 PM, Dave Brosius wrote:
Sure, but both of
Sure, but both of those algorithms are n^2, which is a bit painful,
especially given all the pointer chasing that occurs with iterators.
On 09/11/2016 08:20 AM, Peter Levart wrote:
Hi,
Even if the elements are not comparable, you could rely on the fact
that Collection(s) usually create itera
Hi,
Even if the elements are not comparable, you could rely on the fact that
Collection(s) usually create iterators with stable iteration order, so
you could do the following:
Set set = Set.of(1, 2, 3, 4);
Iterator it1 = set.iterator();
for (int n1 = 0; it1.hasNext()
Hello!
As your keys are comparable, you can create normal iterators and
filter the results like this:
for(String v1 : s) {
for(String v2 : s) {
if(v1.compareTo(v2) < 0) {
System.out.println(v1 + " <-->" + v2);
}
}
}
Or using Stream API:
s.stream().flatMap(v1 -> s.stream()
ls
(this one is not true anymore because any JITs routinely devirtualize this
kind of call).
cheers,
Rémi
- Mail original -
De: "Dave Brosius"
À: "Louis Wasserman" , "Jonathan Bluett-Duncan"
Cc: core-libs-dev@openjdk.java.net
Envoyé: Dimanche 11 Septem
libs-dev@openjdk.java.net
> Envoyé: Dimanche 11 Septembre 2016 02:23:41
> Objet: Re: Make iterators cloneable?
>>> Iterators reading from a BufferedReader
>
> yes that's true. altho given the contract of Cloneable, adding the clone
> method on Iterator would be safe, as i
>> Iterators reading from a BufferedReader
yes that's true. altho given the contract of Cloneable, adding the clone
method on Iterator would be safe, as it would only be available if the
real implementing class 'extends Cloneable'... it's actually kind of
funny that Object methods aren't avail
Some iterators might be. Many may not be. Certainly Iterator as an
interface has been out there for long enough there are Iterator
implementations out there that aren't cloneable -- say, Iterators reading
from a BufferedReader, where there really won't be any way to do what
you're hoping for; Buf
Yes Louis is correct.
I want the pair wise associations or all elements of a set.
Fee-Fi
Fee-Fo
Fee-Fum
Fi-Fo
Fi-Fum
Fo-Fum
the independent iterators produce Fee-Fee (etc) as well as the duplicate
Fee-Fi and Fi-Fee (etc), both of which i don't want.
This is obviously simplistic with i
Ah okay Louis, if that's the case then that certainly makes sense, and I'd
agree that there's no good way of doing so, as one would need to copy the
set into a list.
Dave, did Louis hit the mark? If not, would you kindly go into further
detail as to exactly what it is you're trying to do?
Best,
J
Hi Dave,
Rather than using Iterator.clone(), how about you just call
collection.iterator() 2 times to return 2 unique, non-same iterators;
something like the following:
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
p
15 matches
Mail list logo