Closed GoogleCodeExporter closed 9 years ago
I could have sworn there was another issue requesting something like this, but
I couldn't find it.
Original comment by cgdecker@google.com
on 2 Jul 2013 at 3:49
Internally we've called this collapseDuplicates, but I don't see an issue under
that name, either.
Original comment by cpov...@google.com
on 2 Jul 2013 at 4:06
maybe this is related:
https://code.google.com/p/guava-libraries/issues/detail?id=524
Original comment by egor@technoparkcorp.com
on 9 Aug 2013 at 7:41
In my case an Iterable is of unlimited size. That's why I can't save it
anywhere and then remove duplicates. I really need to filter them out on the
fly. That's why iterables are for, right? To be optionally unlimited in size
Original comment by egor@technoparkcorp.com
on 9 Aug 2013 at 7:58
[deleted comment]
[deleted comment]
This is how I implemented it in my project:
public final class Distinct<T> implements Iterator<T> {
private final transient Iterator<T> origin;
private final transient Set<T> seen = new LinkedHashSet<T>(0);
private final transient AtomicReference<T> recent =
new AtomicReference<T>();
public Distinct(final Iterator<T> iterator) {
this.origin = iterator;
}
@Override
public boolean hasNext() {
while (this.recent.get() == null && this.origin.hasNext()) {
final T next = this.origin.next();
if (!this.seen.contains(next)) {
this.seen.add(next);
this.recent.set(next);
}
}
return this.recent.get() != null;
}
@Override
public T next() {
if (!this.hasNext()) {
throw new NoSuchElementException();
}
return this.recent.getAndSet(null);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
Original comment by egor@technoparkcorp.com
on 9 Aug 2013 at 9:23
I'm going to rename this bug to be specifically about sorted iterators, as the
original post requested. Thanks for digging up issue 524 about unsorted inputs.
I'll follow up more there about that case.
Original comment by cpov...@google.com
on 9 Aug 2013 at 7:15
My use case wants a way to take the union of several potentially large subsets
of a common space, presented as sorted iterators. mergeSorted and
collapseDuplicates would do that nicely.
Original comment by phil.h.s...@gmail.com
on 26 Apr 2014 at 6:46
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:12
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:17
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
egor@technoparkcorp.com
on 1 Jul 2013 at 9:24