Skip to content
Permalink
Browse files
Added tests for the tuple intersections(Tuple, Theta) and AnotB(Tuple,
Theta). And found some bugs that are now fixed.
  • Loading branch information
leerho committed Oct 21, 2021
1 parent 4585ddc commit 08b590ad9e1d984f11647e1e7321dc623479febe
Show file tree
Hide file tree
Showing 3 changed files with 421 additions and 449 deletions.
@@ -110,12 +110,12 @@
@SuppressWarnings("unchecked")
public void setA(final Sketch<S> skA) {
if (skA == null) {
reset();
internalReset();
throw new SketchesArgumentException("The input argument <i>A</i> may not be null");
}
summaryFactory_ = skA.getSummaryFactory();
if (skA.isEmpty()) {
reset();
internalReset();
return;
}
//skA is not empty
@@ -238,7 +238,7 @@ public CompactSketch<S> getResult(final boolean reset) {
final CompactSketch<S> result =
new CompactSketch<>(Arrays.copyOfRange(hashArr_, 0, curCount_),
Arrays.copyOfRange(summaryArr_, 0, curCount_), thetaLong_, empty_);
if (reset) { reset(); }
if (reset) { internalReset(); }
return result;
}

@@ -489,14 +489,22 @@ private static <S extends Summary> DataArrays<S> getResultArraysTheta(
}

/**
* Resets this sketch back to the empty state.
* Resets this operation back to the empty state, but keeps the SummaryFactory.
*/
private void reset() {
private void internalReset() {
empty_ = true;
thetaLong_ = Long.MAX_VALUE;
hashArr_ = null;
summaryArr_ = null;
curCount_ = 0;
}

/**
* Resets this operation back to the empty state.
*/
public void reset() {
internalReset();
summaryFactory_ = null;
}

}
@@ -107,6 +107,8 @@ public void intersect(final Sketch<S> tupleSketch) {
if (tupleSketch == null) { throw new SketchesArgumentException("Sketch must not be null"); }
final boolean firstCall = firstCall_;
firstCall_ = false;
// input sketch could be first or next call

final boolean emptyIn = tupleSketch.isEmpty();
if (empty_ || emptyIn) { //empty rule
//Because of the definition of null above and the Empty Rule (which is OR), empty_ must be true.
@@ -115,11 +117,10 @@ public void intersect(final Sketch<S> tupleSketch) {
return;
}

// input sketch could be first or next call
final long thetaLongIn = tupleSketch.getThetaLong();
final int countIn = tupleSketch.getRetainedEntries();
thetaLong_ = min(thetaLong_, thetaLongIn); //Theta rule

final int countIn = tupleSketch.getRetainedEntries();
if (countIn == 0) {
hashTables_.clear();
return;
@@ -180,19 +181,25 @@ public void intersect(final org.apache.datasketches.theta.Sketch thetaSketch, fi
if (summary == null) { throw new SketchesArgumentException("Summary cannot be null."); }
final boolean firstCall = firstCall_;
firstCall_ = false;

// input sketch is not null, could be first or next call

final boolean emptyIn = thetaSketch.isEmpty();
if (empty_ || emptyIn) { //empty rule
//Because of the definition of null above and the Empty Rule (which is OR), empty_ must be true.
//Whatever the current internal state, we make our local empty.
resetToEmpty();
return;
}

final long thetaLongIn = thetaSketch.getThetaLong();
final int countIn = thetaSketch.getRetainedEntries(true);
thetaLong_ = min(thetaLong_, thetaLongIn); //Theta rule
// Empty rule extended in case incoming sketch does not have empty bit properly set
final boolean emptyIn = countIn == 0 && thetaLongIn == Long.MAX_VALUE;
empty_ |= emptyIn; //empty rule
final int countIn = thetaSketch.getRetainedEntries();
if (countIn == 0) {
hashTables_.clear();
return;
}
// input sketch will have valid entries > 0

if (firstCall) {
final org.apache.datasketches.theta.Sketch firstSketch = thetaSketch;
//Copy firstSketch data into local instance hashTables_

0 comments on commit 08b590a

Please sign in to comment.