Skip to content
Permalink
Browse files
interim 4
  • Loading branch information
leerho committed Mar 4, 2022
1 parent 032a9a6 commit ae156ae9985f76dd57e547536b96f0e2247cbe5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
@@ -240,17 +240,16 @@ public static int getMaxSerializedSizeBytes(final int k, final long n) {
}

/**
* Returns the current number of bytes this sketch would require to store in compact form.
* @return the current number of bytes this sketch would require to store in compact form.
* Returns the current compact number of bytes this sketch would require to store.
* @return the current compact number of bytes this sketch would require to store.
*/
public int getCurrentCompactSerializedSizeBytes() {
if (isEmpty()) { return N_LONG_ADR; }
return KllHelper.getSerializedSizeBytes(numLevels_, getNumRetained(), IS_DOUBLE, false);
}

/**
* Returns the current number of bytes this sketch would require to store in updatable form.
* @return the current number of bytes this sketch would require to store in updatable form.
* Returns the current updatable number of bytes this sketch would require to store.
* @return the current updatable number of bytes this sketch would require to store.
*/
public int getCurrentUpdatableSerializedSizeBytes() {
return KllHelper.getSerializedSizeBytes(numLevels_, getNumRetained(), IS_DOUBLE, true);
@@ -240,17 +240,16 @@ public static int getMaxSerializedSizeBytes(final int k, final long n) {
}

/**
* Returns the current number of bytes this sketch would require to store in compact form.
* @return the current number of bytes this sketch would require to store in compact form.
* Returns the current compact number of bytes this sketch would require to store.
* @return the current compact number of bytes this sketch would require to store.
*/
public int getCurrentCompactSerializedSizeBytes() {
if (isEmpty()) { return N_LONG_ADR; }
return KllHelper.getSerializedSizeBytes(numLevels_, getNumRetained(), IS_DOUBLE, false);
}

/**
* Returns the current number of bytes this sketch would require to store in updatable form.
* @return the current number of bytes this sketch would require to store in updatable form.
* Returns the current updatable number of bytes this sketch would require to store.
* @return the current updatable number of bytes this sketch would require to store.
*/
public int getCurrentUpdatableSerializedSizeBytes() {
return KllHelper.getSerializedSizeBytes(numLevels_, getNumRetained(), IS_DOUBLE, true);
@@ -26,6 +26,7 @@
import static org.apache.datasketches.kll.PreambleUtil.DATA_START_ADR_SINGLE_ITEM;
import static org.apache.datasketches.kll.PreambleUtil.MAX_K;
import static org.apache.datasketches.kll.PreambleUtil.MIN_K;
import static org.apache.datasketches.kll.PreambleUtil.N_LONG_ADR;

import org.apache.datasketches.SketchesArgumentException;

@@ -139,15 +140,14 @@ static int getSerializedSizeBytes(final int numLevels, final int numRetained, fi
final boolean updatable) {
int levelsBytes = 0;
if (!updatable) {
if (numLevels == 1 && numRetained == 1) {
return DATA_START_ADR_SINGLE_ITEM + (isDouble ? Double.BYTES : Float.BYTES);
}
if (numRetained == 0) { return N_LONG_ADR; }
if (numRetained == 1) { return DATA_START_ADR_SINGLE_ITEM + (isDouble ? Double.BYTES : Float.BYTES); }
levelsBytes = numLevels * Integer.BYTES;
} else {
levelsBytes = (numLevels + 1) * Integer.BYTES;
}
if (isDouble) {
return DATA_START_ADR_DOUBLE + levelsBytes + (numRetained + 2) * Double.BYTES;
return DATA_START_ADR_DOUBLE + levelsBytes + (numRetained + 2) * Double.BYTES; //+2 is for min & max
} else {
return DATA_START_ADR_FLOAT + levelsBytes + (numRetained + 2) * Float.BYTES;
}

0 comments on commit ae156ae

Please sign in to comment.