Closed numeralnathan closed 4 years ago
Let's say we have the following stream pattern...
... sorted(). distinct(). ...
The distinct operator can be simplified. Instead of putting all of the elements into a Set, the distinct operator only needs to compare to the previous element.
Set
This will reduce the memory usage from O(n) to O(1).
I believe, it's already done in JDK, and we delegate to JDK streams. See https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/stream/DistinctOps.java#L124
Let's say we have the following stream pattern...
The distinct operator can be simplified. Instead of putting all of the elements into a
Set
, the distinct operator only needs to compare to the previous element.This will reduce the memory usage from O(n) to O(1).