Skip to content
Permalink
Browse files
Update changes in FixMikhailsBug
  • Loading branch information
leerho committed Oct 21, 2021
1 parent 8cfe98d commit 4585ddc464bb2e28448c50d5145498624882febd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
@@ -69,6 +69,7 @@
private long[] hashArr_ = null; //always in compact form, not necessarily sorted
private S[] summaryArr_ = null; //always in compact form, not necessarily sorted
private int curCount_ = 0;
private SummaryFactory<S> summaryFactory_;

private static final Method GET_CACHE;

@@ -112,6 +113,7 @@ public void setA(final Sketch<S> skA) {
reset();
throw new SketchesArgumentException("The input argument <i>A</i> may not be null");
}
summaryFactory_ = skA.getSummaryFactory();
if (skA.isEmpty()) {
reset();
return;
@@ -129,8 +131,7 @@ public void setA(final Sketch<S> skA) {

summaryArr_ = da.summaryArr;
if (summaryArr_ == null) {
final SummaryFactory<S> sumFact = ((QuickSelectSketch<S>)skA).getSummaryFactory();
final S summary = sumFact.newSummary();
final S summary = skA.getSummaryFactory().newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArr_ = (S[]) Array.newInstance(summaryType, 0);
}
@@ -159,6 +160,12 @@ public void notB(final Sketch<S> skB) {
//skB is not empty
final long thetaLongB = skB.getThetaLong();
thetaLong_ = Math.min(thetaLong_, thetaLongB);
summaryFactory_ = skB.getSummaryFactory();
if (summaryArr_ == null) {
final S summary = summaryFactory_.newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArr_ = (S[]) Array.newInstance(summaryType, 0);
}

//process B
final DataArrays<S> daB = getResultArraysTuple(thetaLong_, curCount_, hashArr_, summaryArr_, skB);
@@ -168,12 +175,6 @@ public void notB(final Sketch<S> skB) {
curCount_ = hashArr_.length;

summaryArr_ = daB.summaryArr;
if (summaryArr_ == null) {
final SummaryFactory<S> sumFact = ((QuickSelectSketch<S>)skB).getSummaryFactory();
final S summary = sumFact.newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArr_ = (S[]) Array.newInstance(summaryType, 0);
}

empty_ = curCount_ == 0 && thetaLong_ == Long.MAX_VALUE;
}
@@ -197,11 +198,17 @@ public void notB(final Sketch<S> skB) {
*
* @param skB The incoming Theta sketch for the second (or following) argument <i>B</i>.
*/
@SuppressWarnings("unchecked")
public void notB(final org.apache.datasketches.theta.Sketch skB) {
if (empty_ || skB == null || skB.isEmpty()) { return; }
//skB is not empty
final long thetaLongB = skB.getThetaLong();
thetaLong_ = Math.min(thetaLong_, thetaLongB);
if (summaryArr_ == null) {
final S summary = summaryFactory_.newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArr_ = (S[]) Array.newInstance(summaryType, 0);
}

//process B
final DataArrays<S> daB = getResultArraysTheta(thetaLong_, curCount_, hashArr_, summaryArr_, skB);
@@ -212,7 +219,6 @@ public void notB(final org.apache.datasketches.theta.Sketch skB) {

summaryArr_ = daB.summaryArr;


empty_ = curCount_ == 0 && thetaLong_ == Long.MAX_VALUE;
}

@@ -281,8 +287,7 @@ CompactSketch<S> aNotB(final Sketch<S> skA, final Sketch<S> skB) {

S[] summaryArrA = da.summaryArr;
if (summaryArrA == null) {
final SummaryFactory<S> sumFact = ((QuickSelectSketch<S>)skA).getSummaryFactory();
final S summary = sumFact.newSummary();
final S summary = skA.getSummaryFactory().newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArrA = (S[]) Array.newInstance(summaryType, 0);
}
@@ -348,8 +353,7 @@ CompactSketch<S> aNotB(final Sketch<S> skA, final org.apache.datasketches.theta.

S[] summaryArrA = da.summaryArr;
if (summaryArrA == null) {
final SummaryFactory<S> sumFact = ((QuickSelectSketch<S>)skA).getSummaryFactory();
final S summary = sumFact.newSummary();
final S summary = skA.getSummaryFactory().newSummary();
final Class<S> summaryType = (Class<S>)summary.getClass();
summaryArrA = (S[]) Array.newInstance(summaryType, 0);
}
@@ -51,7 +51,7 @@ private enum Flags { IS_BIG_ENDIAN, IS_IN_SAMPLING_MODE, IS_EMPTY, HAS_ENTRIES,
private int lgCurrentCapacity_;
private final int lgResizeFactor_;
private int count_;
private final SummaryFactory<S> summaryFactory_;
//private final SummaryFactory<S> summaryFactory_;
private final float samplingProbability_;
private int rebuildThreshold_;
private long[] hashTable_;
@@ -127,8 +127,8 @@ private enum Flags { IS_BIG_ENDIAN, IS_IN_SAMPLING_MODE, IS_EMPTY, HAS_ENTRIES,
nomEntries_ = ceilingPowerOf2(nomEntries);
lgResizeFactor_ = lgResizeFactor;
samplingProbability_ = samplingProbability;
summaryFactory_ = summaryFactory;
thetaLong_ = (long) (Long.MAX_VALUE * (double) samplingProbability);
summaryFactory_ = summaryFactory; //super
thetaLong_ = (long) (Long.MAX_VALUE * (double) samplingProbability); //super
lgCurrentCapacity_ = Integer.numberOfTrailingZeros(startingSize);
hashTable_ = new long[startingSize];
summaryTable_ = null; // wait for the first summary to call Array.newInstance()
@@ -425,10 +425,6 @@ void setEmpty(final boolean value) {
empty_ = value;
}

SummaryFactory<S> getSummaryFactory() {
return summaryFactory_;
}

int findOrInsert(final long hash) {
final int index = HashOperations.hashSearchOrInsert(hashTable_, lgCurrentCapacity_, hash);
if (index < 0) {
@@ -36,6 +36,7 @@

long thetaLong_;
boolean empty_ = true;
protected SummaryFactory<S> summaryFactory_;

Sketch() {}

@@ -152,6 +153,10 @@ public boolean isEstimationMode() {
*/
public abstract int getCountLessThanThetaLong(final long thetaLong);

public SummaryFactory<S> getSummaryFactory() {
return summaryFactory_;
}

/**
* Gets the value of theta as a double between zero and one
* @return the value of theta as a double

0 comments on commit 4585ddc

Please sign in to comment.