You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by pa...@apache.org on 2020/12/03 12:00:38 UTC

[incubator-datasketches-java] 01/01: two new constants for ReqSketch; allowing to change constants (for experiments)

This is an automated email from the ASF dual-hosted git repository.

pavelvesely pushed a commit to branch ReqExperiment
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git

commit 63486c0ca1d0e102114d4e2b372b40a815614544
Author: Pavel Vesely <ve...@iuuk.mff.cuni.cz>
AuthorDate: Wed Dec 2 23:44:42 2020 +0100

    two new constants for ReqSketch; allowing to change constants (for experiments)
---
 .../org/apache/datasketches/req/BaseReqSketch.java    |  4 ++++
 .../org/apache/datasketches/req/ReqCompactor.java     |  9 ++++++---
 .../java/org/apache/datasketches/req/ReqSketch.java   | 19 ++++++++++++++++---
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/req/BaseReqSketch.java b/src/main/java/org/apache/datasketches/req/BaseReqSketch.java
index b4b082d..8c2602d 100644
--- a/src/main/java/org/apache/datasketches/req/BaseReqSketch.java
+++ b/src/main/java/org/apache/datasketches/req/BaseReqSketch.java
@@ -254,4 +254,8 @@ abstract class BaseReqSketch {
    */
   public abstract String viewCompactorDetail(String fmt, boolean allData);
 
+  public void set_INIT_NUMBER_OF_SECTIONS(final byte val) {}
+  public void set_NOM_CAPACITY_MULTIPLIER(final float val){}
+  public void set_MIN_K(final int val){}
+  public void set_LAZY_COMPRESSION(final boolean val) {}
 }
diff --git a/src/main/java/org/apache/datasketches/req/ReqCompactor.java b/src/main/java/org/apache/datasketches/req/ReqCompactor.java
index bcffaca..308b8f8 100644
--- a/src/main/java/org/apache/datasketches/req/ReqCompactor.java
+++ b/src/main/java/org/apache/datasketches/req/ReqCompactor.java
@@ -22,6 +22,7 @@ package org.apache.datasketches.req;
 import static java.lang.Math.round;
 import static org.apache.datasketches.Util.numberOfTrailingOnes;
 import static org.apache.datasketches.req.ReqSketch.INIT_NUMBER_OF_SECTIONS;
+import static org.apache.datasketches.req.ReqSketch.NOM_CAPACITY_MULTIPLIER;
 import static org.apache.datasketches.req.ReqSketch.MIN_K;
 
 import java.util.Random;
@@ -122,6 +123,7 @@ class ReqCompactor {
     final int startRetItems = buf.getLength();
     final int startNomCap = getNomCapacity();
     // choose a part of the buffer to compact
+    
     final int secsToCompact = Math.min(numberOfTrailingOnes(state) + 1, numSections);
     final long compactionRange = computeCompactionRange(secsToCompact);
     final int compactionStart = (int) (compactionRange & 0xFFFF_FFFFL); //low 32
@@ -169,8 +171,8 @@ class ReqCompactor {
    * Sets the current nominal capacity of this compactor.
    * @return the current maximum capacity of this compactor.
    */
-  int getNomCapacity() {
-    final int nCap = 2 * numSections * sectionSize;
+  int getNomCapacity() { // TODO implement caching the result?
+    final int nCap = (int)(NOM_CAPACITY_MULTIPLIER * numSections * sectionSize);
     return nCap;
   }
 
@@ -232,7 +234,7 @@ class ReqCompactor {
   private boolean ensureEnoughSections() {
     final float szf;
     final int ne;
-    if (state >= 1L << numSections - 1
+    if (state >= 1L << numSections - 1 //TODO try adding: && sectionSize > MIN_K
         && (ne = nearestEven(szf = (float)(sectionSizeFlt / SQRT2))) >= MIN_K)
     {
       sectionSizeFlt = szf;
@@ -254,6 +256,7 @@ class ReqCompactor {
   private long computeCompactionRange(final int secsToCompact) {
     final int bufLen = buf.getLength();
     int nonCompact = getNomCapacity() / 2 + (numSections - secsToCompact) * sectionSize;
+    // TODO: alternative: int nonCompact = (2 * numSections - secsToCompact) * sectionSize;
     //make compacted region even:
     nonCompact = (bufLen - nonCompact & 1) == 1 ? nonCompact + 1 : nonCompact;
     final long low =  hra ? 0                   : nonCompact;
diff --git a/src/main/java/org/apache/datasketches/req/ReqSketch.java b/src/main/java/org/apache/datasketches/req/ReqSketch.java
index 8674de1..c93f8b7 100644
--- a/src/main/java/org/apache/datasketches/req/ReqSketch.java
+++ b/src/main/java/org/apache/datasketches/req/ReqSketch.java
@@ -71,8 +71,20 @@ import org.apache.datasketches.memory.Memory;
 public class ReqSketch extends BaseReqSketch {
   //static finals
   private static final String LS = System.getProperty("line.separator");
-  static final int INIT_NUMBER_OF_SECTIONS = 3;
-  static final int MIN_K = 4;
+  static byte INIT_NUMBER_OF_SECTIONS = 3; // TODO: return final
+  static float NOM_CAPACITY_MULTIPLIER = 2f; // should be at least 2 // PV: TMP: FOR TESTING PURPOSES
+  static int MIN_K = 4;
+  static boolean LAZY_COMPRESSION = true; // PV: TMP: FOR TESTING PURPOSES
+  
+  @Override
+  public void set_INIT_NUMBER_OF_SECTIONS(final byte val) { INIT_NUMBER_OF_SECTIONS = val; }
+  @Override
+  public void set_NOM_CAPACITY_MULTIPLIER(final float val) { NOM_CAPACITY_MULTIPLIER = val; }
+  @Override
+  public void set_MIN_K(final int val) { MIN_K = val; }
+  @Override
+  public void set_LAZY_COMPRESSION(final boolean val) { LAZY_COMPRESSION = val; }
+  
   private static final double relRseFactor = sqrt(0.0512 / INIT_NUMBER_OF_SECTIONS);
   private static final double fixRseFactor = .06;
   //finals
@@ -125,6 +137,7 @@ public class ReqSketch extends BaseReqSketch {
     maxNomSize = other.maxNomSize;
     minValue = other.minValue;
     maxValue = other.maxValue;
+
     ltEq = other.ltEq;
     reqDebug = other.reqDebug;
     //aux does not need to be copied
@@ -182,7 +195,7 @@ public class ReqSketch extends BaseReqSketch {
         compactors.get(h + 1).getBuffer().mergeSortIn(promoted);
         retItems += cReturn.deltaRetItems;
         maxNomSize += cReturn.deltaNomSize;
-        if (retItems < maxNomSize) { break; }
+        if (LAZY_COMPRESSION && retItems < maxNomSize) { break; } 
       }
     }
     aux = null;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org