Skip to content
Permalink
Browse files
Interim 5
  • Loading branch information
leerho committed Mar 5, 2022
1 parent ae156ae commit b662bb04ae9aa3d801b40a95cc56ac029a752743
Showing 10 changed files with 466 additions and 332 deletions.
@@ -26,6 +26,7 @@
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.round;
import static org.apache.datasketches.kll.PreambleUtil.DEFAULT_M;
import static org.apache.datasketches.kll.PreambleUtil.MAX_K;
import static org.apache.datasketches.kll.PreambleUtil.MIN_K;

@@ -50,16 +51,15 @@ abstract class BaseKllSketch {
* 5) curTotalCap = items_.length = levels_[numLevels_].
*/

final int k_; // configured value of K
final int m_; // configured minimum buffer "width", Must always be DEFAULT_M for now.
static final int M = DEFAULT_M; // configured minimum buffer "width", Must always be 8 for now.
private final int k_; // configured value of K
private int dyMinK_; // dynamic minK for error estimation after merging with different k
private long n_; // number of items input into this sketch
private int numLevels_; // one-based number of current levels,
private int[] levels_; // array of index offsets into the items[]. Size = numLevels + 1.
private boolean isLevelZeroSorted_;

int minK_; // for error estimation after merging with different k
long n_; // number of items input into this sketch
int numLevels_; // one-based number of current levels,
int[] levels_; // array of index offsets into the items[]. Size = numLevels + 1.
boolean isLevelZeroSorted_;

final boolean compatible; //compatible with quantiles sketch treatment of rank 0.0 and 1.0.
private final boolean compatible; //compatible with quantiles sketch treatment of rank 0.0 and 1.0.
static final Random random = new Random();

/**
@@ -71,14 +71,77 @@ abstract class BaseKllSketch {
BaseKllSketch(final int k, final int m, final boolean compatible) {
KllHelper.checkK(k);
k_ = k;
minK_ = k;
m_ = m;
dyMinK_ = k;
numLevels_ = 1;
levels_ = new int[] {k, k};
isLevelZeroSorted_ = false;
this.compatible = compatible;
}

int getDyMinK() {
return dyMinK_;
}

void setDyMinK(final int dyMinK) {
dyMinK_ = dyMinK;
}

int getNumLevels() {
return numLevels_;
}

void setNumLevels(final int numLevels) {
numLevels_ = numLevels;
}

void incNumLevels() {
numLevels_++;
}

int[] getLevelsArray() {
return levels_;
}

int getLevelsArrayAt(final int index) {
return levels_[index];
}

void setLevelsArray(final int[] levels) {
this.levels_ = levels;
}

void setLevelsArrayAt(final int index, final int value) {
this.levels_[index] = value;
}

void setLevelsArrayAtPlusEq(final int index, final int plusEq) {
this.levels_[index] += plusEq;
}

void setLevelsArrayAtMinusEq(final int index, final int minusEq) {
this.levels_[index] -= minusEq;
}

boolean isLevelZeroSorted() {
return isLevelZeroSorted_;
}

void setLevelZeroSorted(final boolean sorted) {
this.isLevelZeroSorted_ = sorted;
}

boolean isCompatible() {
return this.compatible;
}

void setN(final long n) {
n_ = n;
}

void incN() {
n_++;
}

// public functions

/**
@@ -89,6 +152,14 @@ public int getK() {
return k_;
}

/**
* Returns the length of the input stream.
* @return stream length
*/
public long getN() {
return n_;
}

/**
* Gets the approximate value of <em>k</em> to use given epsilon, the normalized rank error.
* @param epsilon the normalized rank error between zero and one.
@@ -113,14 +184,6 @@ public static int getKFromEpsilon(final double epsilon, final boolean pmf) {
return max(MIN_K, min(MAX_K, k));
}

/**
* Returns the length of the input stream.
* @return stream length
*/
public long getN() {
return n_;
}

/**
* Gets the approximate rank error of this sketch normalized as a fraction between zero and one.
* @param pmf if true, returns the "double-sided" normalized rank error for the getPMF() function.
@@ -130,7 +193,7 @@ public long getN() {
* @see KllDoublesSketch
*/
public double getNormalizedRankError(final boolean pmf) {
return KllHelper.getNormalizedRankError(minK_, pmf);
return KllHelper.getNormalizedRankError(dyMinK_, pmf);
}

/**
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.datasketches.kll;

//import static java.lang.Math.max;
//import static java.lang.Math.min;
//import static org.apache.datasketches.Util.isOdd;
//import static org.apache.datasketches.kll.KllHelper.getAllLevelStatsGivenN;
//import static org.apache.datasketches.kll.PreambleUtil.DATA_START_ADR_DOUBLE;
//import static org.apache.datasketches.kll.PreambleUtil.DATA_START_ADR_SINGLE_ITEM;
//import static org.apache.datasketches.kll.PreambleUtil.DEFAULT_K;
//import static org.apache.datasketches.kll.PreambleUtil.DEFAULT_M;
//import static org.apache.datasketches.kll.PreambleUtil.DOUBLES_SKETCH_BIT_MASK;
//import static org.apache.datasketches.kll.PreambleUtil.EMPTY_BIT_MASK;
//import static org.apache.datasketches.kll.PreambleUtil.FAMILY_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.FLAGS_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.K_SHORT_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.LEVEL_ZERO_SORTED_BIT_MASK;
//import static org.apache.datasketches.kll.PreambleUtil.MIN_K_SHORT_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.M_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.NUM_LEVELS_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.N_LONG_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.PREAMBLE_INTS_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.PREAMBLE_INTS_DOUBLE;
//import static org.apache.datasketches.kll.PreambleUtil.PREAMBLE_INTS_EMPTY_SINGLE;
//import static org.apache.datasketches.kll.PreambleUtil.SERIAL_VERSION_EMPTY_FULL;
//import static org.apache.datasketches.kll.PreambleUtil.SERIAL_VERSION_SINGLE;
//import static org.apache.datasketches.kll.PreambleUtil.SER_VER_BYTE_ADR;
//import static org.apache.datasketches.kll.PreambleUtil.SINGLE_ITEM_BIT_MASK;
//import static org.apache.datasketches.kll.PreambleUtil.UPDATABLE_BIT_MASK;
//
//import java.util.Arrays;
//
//import org.apache.datasketches.Family;
//import org.apache.datasketches.SketchesArgumentException;
//import org.apache.datasketches.Util;
//import org.apache.datasketches.kll.KllHelper.LevelStats;
//import org.apache.datasketches.kll.PreambleUtil.MemoryCheck;
//import org.apache.datasketches.memory.Memory;
//import org.apache.datasketches.memory.WritableMemory;

/**
* Please refer to the documentation in the package-info:<br>
* {@link org.apache.datasketches.kll}
*/
public class KllDirectDoublesSketch {



}

0 comments on commit b662bb0

Please sign in to comment.