You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2020/07/07 23:37:11 UTC
[incubator-datasketches-java] 08/10: Allow for future extension of
Theta.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch Refactor_Theta_Tuple
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git
commit 65897ed314bc9911e43d8aa64c06c62894f29337
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sat Jul 4 11:47:52 2020 -0700
Allow for future extension of Theta.
---
.../theta/DirectQuickSelectSketch.java | 8 +++++--
.../apache/datasketches/theta/HeapAlphaSketch.java | 1 -
.../datasketches/theta/HeapQuickSelectSketch.java | 11 +++++----
.../datasketches/theta/UpdateReturnState.java | 26 ++++++++++++++++------
4 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketch.java b/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketch.java
index 9309194..dc34bc5 100644
--- a/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketch.java
+++ b/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketch.java
@@ -52,6 +52,8 @@ import static org.apache.datasketches.theta.Rebuilder.moveAndResize;
import static org.apache.datasketches.theta.Rebuilder.quickSelectAndRebuild;
import static org.apache.datasketches.theta.Rebuilder.resize;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncremented;
+import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedRebuilt;
+import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedResized;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedDuplicate;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
@@ -274,6 +276,7 @@ class DirectQuickSelectSketch extends DirectQuickSelectSketchR {
: "lgArr: " + lgArrLongs + ", lgNom: " + lgNomLongs;
//rebuild, refresh curCount based on # values in the hashtable.
quickSelectAndRebuild(wmem_, preambleLongs, lgNomLongs);
+ return InsertedCountIncrementedRebuilt;
} //end of rebuild, exit
else { //Not at full size, resize. Should not get here if lgRF = 0 and memCap is too small.
@@ -285,6 +288,7 @@ class DirectQuickSelectSketch extends DirectQuickSelectSketchR {
//lgArrLongs will change; thetaLong, curCount will not
resize(wmem_, preambleLongs, lgArrLongs, tgtLgArrLongs);
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, tgtLgArrLongs);
+ return InsertedCountIncrementedResized;
} //end of Expand in current memory, exit.
else {
@@ -304,10 +308,10 @@ class DirectQuickSelectSketch extends DirectQuickSelectSketchR {
wmem_ = newDstMem;
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, tgtLgArrLongs);
-
+ return InsertedCountIncrementedResized;
} //end of Request more memory to resize
} //end of resize
- }
+ } //end of isOutOfSpace
return InsertedCountIncremented;
}
diff --git a/src/main/java/org/apache/datasketches/theta/HeapAlphaSketch.java b/src/main/java/org/apache/datasketches/theta/HeapAlphaSketch.java
index 2561b44..b0782ec 100644
--- a/src/main/java/org/apache/datasketches/theta/HeapAlphaSketch.java
+++ b/src/main/java/org/apache/datasketches/theta/HeapAlphaSketch.java
@@ -308,7 +308,6 @@ final class HeapAlphaSketch extends HeapUpdateSketch {
//The over-theta test
if (HashOperations.continueCondition(thetaLong_, hash)) {
- // very very unlikely that hash == Long.MAX_VALUE. It is ignored just as zero is ignored.
return RejectedOverTheta; //signal that hash was rejected due to theta.
}
diff --git a/src/main/java/org/apache/datasketches/theta/HeapQuickSelectSketch.java b/src/main/java/org/apache/datasketches/theta/HeapQuickSelectSketch.java
index d6303bf..b3dcf6b 100644
--- a/src/main/java/org/apache/datasketches/theta/HeapQuickSelectSketch.java
+++ b/src/main/java/org/apache/datasketches/theta/HeapQuickSelectSketch.java
@@ -36,6 +36,8 @@ import static org.apache.datasketches.theta.PreambleUtil.extractP;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncremented;
+import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedRebuilt;
+import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedResized;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedDuplicate;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
@@ -258,11 +260,12 @@ class HeapQuickSelectSketch extends HeapUpdateSketch {
//must rebuild or resize
if (lgArrLongs_ <= lgNomLongs_) { //resize
resizeCache();
+ return InsertedCountIncrementedResized;
}
- else { //Already at tgt size, must rebuild
- assert (lgArrLongs_ == (lgNomLongs_ + 1)) : "lgArr: " + lgArrLongs_ + ", lgNom: " + lgNomLongs_;
- quickSelectAndRebuild(); //Changes thetaLong_, curCount_, reassigns cache
- }
+ //Already at tgt size, must rebuild
+ assert (lgArrLongs_ == (lgNomLongs_ + 1)) : "lgArr: " + lgArrLongs_ + ", lgNom: " + lgNomLongs_;
+ quickSelectAndRebuild(); //Changes thetaLong_, curCount_, reassigns cache
+ return InsertedCountIncrementedRebuilt;
}
return InsertedCountIncremented;
}
diff --git a/src/main/java/org/apache/datasketches/theta/UpdateReturnState.java b/src/main/java/org/apache/datasketches/theta/UpdateReturnState.java
index df95c9d..a6d5348 100644
--- a/src/main/java/org/apache/datasketches/theta/UpdateReturnState.java
+++ b/src/main/java/org/apache/datasketches/theta/UpdateReturnState.java
@@ -27,39 +27,51 @@ package org.apache.datasketches.theta;
public enum UpdateReturnState {
/**
- * Indicates that the value was accepted into the sketch and the retained count was incremented.
+ * The hash was accepted into the sketch and the retained count was incremented.
*/
InsertedCountIncremented, //all UpdateSketches
/**
- * Indicates that the value was accepted into the sketch and the retained count was not incremented.
+ * The hash was accepted into the sketch, the retained count was incremented.
+ * The current cache was out of room and resized larger based on the Resize Factor.
+ */
+ InsertedCountIncrementedResized, //used by HeapQuickSelectSketch
+
+ /**
+ * The hash was accepted into the sketch, the retained count was incremented.
+ * The current cache was out of room and at maximum size, so the cache was rebuilt.
+ */
+ InsertedCountIncrementedRebuilt, //used by HeapQuickSelectSketch
+
+ /**
+ * The hash was accepted into the sketch and the retained count was not incremented.
*/
InsertedCountNotIncremented, //used by enhancedHashInsert for Alpha
/**
- * Indicates that the value was inserted into the local concurrent buffer,
+ * The hash was inserted into the local concurrent buffer,
* but has not yet been propagated to the concurrent shared sketch.
*/
ConcurrentBufferInserted, //used by ConcurrentHeapThetaBuffer
/**
- * Indicates that the value has been propagated to the concurrent shared sketch.
+ * The hash has been propagated to the concurrent shared sketch.
* This does not reflect the action taken by the shared sketch.
*/
ConcurrentPropagated, //used by ConcurrentHeapThetaBuffer
/**
- * Indicates that the value was rejected as a duplicate.
+ * The hash was rejected as a duplicate.
*/
RejectedDuplicate, //all UpdateSketches hashUpdate(), enhancedHashInsert
/**
- * Indicates that the value was rejected because it was null or empty.
+ * The hash was rejected because it was null or empty.
*/
RejectedNullOrEmpty, //UpdateSketch.update(arr[])
/**
- * Indicates that the value was rejected because the hash value was negative, zero or
+ * The hash was rejected because the value was negative, zero or
* greater than theta.
*/
RejectedOverTheta; //all UpdateSketches.hashUpdate()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org