leerho commented on a change in pull request #377:
URL: https://github.com/apache/datasketches-java/pull/377#discussion_r765227241
##########
File path: src/main/java/org/apache/datasketches/tuple/Union.java
##########
@@ -134,64 +130,78 @@ public void union(final
org.apache.datasketches.theta.Sketch thetaSketch, final
if (thetaSketch == null || thetaSketch.isEmpty()) { return; }
empty_ = false;
final long thetaIn = thetaSketch.getThetaLong();
- if (thetaIn < thetaLong_) { thetaLong_ = thetaIn; }
+ thetaLong_ = min(thetaIn, thetaLong_);
final org.apache.datasketches.theta.HashIterator it =
thetaSketch.iterator();
while (it.next()) {
qsk_.merge(it.get(), summary, summarySetOps_); //copies summary
}
- if (qsk_.thetaLong_ < thetaLong_) {
- thetaLong_ = qsk_.thetaLong_;
- }
+ thetaLong_ = min(thetaLong_, qsk_.thetaLong_);
}
+
/**
* Gets the result of a sequence of stateful <i>union</i> operations as an
unordered CompactSketch
- * @return result of the stateful unions so far
+ * @return result of the stateful unions so far. The state of this operation
is not reset after the
+ * result is returned.
*/
@SuppressWarnings("unchecked")
public CompactSketch<S> getResult() {
+ return getResult(false);
+ }
+
+ /**
+ * Gets the result of a sequence of stateful <i>union</i> operations as an
unordered CompactSketch.
+ * @param reset If <i>true</i>, clears this operator to the empty state
after this result is
+ * returned. Set this to <i>false</i> if you wish to obtain an intermediate
result.
+ * @return result of the stateful union
+ */
+ @SuppressWarnings("unchecked")
+ public CompactSketch<S> getResult(final boolean reset) {
+ final CompactSketch<S> result;
if (empty_) {
- return qsk_.compact();
- }
- if (thetaLong_ >= qsk_.thetaLong_ && qsk_.getRetainedEntries() <=
qsk_.getNominalEntries()) {
- return qsk_.compact();
- }
- long theta = min(thetaLong_, qsk_.thetaLong_);
+ result = qsk_.compact();
+ } else if (thetaLong_ >= qsk_.thetaLong_ && qsk_.getRetainedEntries() <=
qsk_.getNominalEntries()) {
+ result = qsk_.compact();
+ } else {
+ long theta = min(thetaLong_, qsk_.thetaLong_);
+ int numHashes = 0;
Review comment:
I have cleaned up this section and added comments so that I could figure
out what exactly was going on :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]