Skip to content

Commit

Permalink
Changes as a result of 2nd reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
leerho committed Nov 3, 2021
1 parent 9de5cd7 commit 8fd253e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 56 deletions.
42 changes: 21 additions & 21 deletions src/main/java/org/apache/datasketches/SetOperationCornerCases.java
Expand Up @@ -73,55 +73,55 @@ public String getDesc() {
}

public enum CornerCase {
ResultDegen_ResultDegen(0, "A{>1.0, 0, F} ; B{>1.0, 0, F}",
ResultDegen_ResultDegen(0, "A{<1.0, 0, F} ; B{<1.0, 0, F}",
IntersectResult.RESULTDEGEN_MIN_0_F, AnotbResult.RESULTDEGEN_MIN_0_F), //0
ResultDegen_NewDegen(01, "A{>1.0, 0, F} ; B{>1.0, 0, T}",
ResultDegen_NewDegen(01, "A{<1.0, 0, F} ; B{<1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.RESULTDEGEN_THA_0_F), //1
ResultDegen_Estimation(02, "A{>1.0, 0, F} ; B{>1.0,>0, F}",
ResultDegen_Estimation(02, "A{<1.0, 0, F} ; B{<1.0,>0, F}",
IntersectResult.RESULTDEGEN_MIN_0_F, AnotbResult.RESULTDEGEN_MIN_0_F), //2
ResultDegen_New(05, "A{>1.0, 0, F} ; B{ 1.0, 0, T}",
ResultDegen_New(05, "A{<1.0, 0, F} ; B{ 1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.RESULTDEGEN_THA_0_F), //5
ResultDegen_Exact(06, "A{>1.0, 0, F} ; B{ 1.0,>0, F}",
ResultDegen_Exact(06, "A{<1.0, 0, F} ; B{ 1.0,>0, F}",
IntersectResult.RESULTDEGEN_MIN_0_F, AnotbResult.RESULTDEGEN_THA_0_F), //6

NewDegen_ResultDegen(010, "A{>1.0, 0, T} ; B{>1.0, 0, F}",
NewDegen_ResultDegen(010, "A{<1.0, 0, T} ; B{<1.0, 0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //8
NewDegen_NewDegen(011, "A{>1.0, 0, T} ; B{>1.0, 0, T}",
NewDegen_NewDegen(011, "A{<1.0, 0, T} ; B{<1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //9
NewDegen_Estimation(012, "A{>1.0, 0, T} ; B{>1.0,>0, F}",
NewDegen_Estimation(012, "A{<1.0, 0, T} ; B{<1.0,>0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //10
NewDegen_New(015, "A{>1.0, 0, T} ; B{ 1.0, 0, T}",
NewDegen_New(015, "A{<1.0, 0, T} ; B{ 1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //13
NewDegen_Exact(016, "A{>1.0, 0, T} ; B{ 1.0,>0, F}",
NewDegen_Exact(016, "A{<1.0, 0, T} ; B{ 1.0,>0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //14

Estimation_ResultDegen(020, "A{>1.0,>0, F} ; B{>1.0, 0, F}",
Estimation_ResultDegen(020, "A{<1.0,>0, F} ; B{<1.0, 0, F}",
IntersectResult.RESULTDEGEN_MIN_0_F, AnotbResult.SKA_TRIM), //16
Estimation_NewDegen(021, "A{>1.0,>0, F} ; B{>1.0, 0, T}",
Estimation_NewDegen(021, "A{<1.0,>0, F} ; B{<1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.SKETCH_A), //17
Estimation_Estimation(022, "A{>1.0,>0, F} ; B{>1.0,>0, F}",
Estimation_Estimation(022, "A{<1.0,>0, F} ; B{<1.0,>0, F}",
IntersectResult.FULL_INTER, AnotbResult.FULL_ANOTB), //18
Estimation_New(025, "A{>1.0,>0, F} ; B{ 1.0, 0, T}",
Estimation_New(025, "A{<1.0,>0, F} ; B{ 1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.SKETCH_A), //21
Estimation_Exact(026, "A{>1.0,>0, F} ; B{ 1.0,>0, F}",
Estimation_Exact(026, "A{<1.0,>0, F} ; B{ 1.0,>0, F}",
IntersectResult.FULL_INTER, AnotbResult.FULL_ANOTB), //22

New_ResultDegen(050, "A{ 1.0, 0, T} ; B{>1.0, 0, F}",
New_ResultDegen(050, "A{ 1.0, 0, T} ; B{<1.0, 0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //40
New_NewDegen(051, "A{ 1.0, 0, T} ; B{>1.0, 0, T}",
New_NewDegen(051, "A{ 1.0, 0, T} ; B{<1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //41
New_Estimation(052, "A{ 1.0, 0, T} ; B{>1.0,>0, F}",
New_Estimation(052, "A{ 1.0, 0, T} ; B{<1.0,>0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //42
New_New(055, "A{ 1.0, 0, T} ; B{ 1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //45
New_Exact(056, "A{ 1.0, 0, T} ; B{ 1.0,>0, F}",
IntersectResult.NEW_1_0_T, AnotbResult.NEW_1_0_T), //46

Exact_ResultDegen(060, "A{ 1.0,>0, F} ; B{>1.0, 0, F}",
Exact_ResultDegen(060, "A{ 1.0,>0, F} ; B{<1.0, 0, F}",
IntersectResult.RESULTDEGEN_MIN_0_F, AnotbResult.SKA_TRIM), //48
Exact_NewDegen(061, "A{ 1.0,>0, F} ; B{>1.0, 0, T}",
Exact_NewDegen(061, "A{ 1.0,>0, F} ; B{<1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.SKETCH_A), //49
Exact_Estimation(062, "A{ 1.0,>0, F} ; B{>1.0,>0, F}",
Exact_Estimation(062, "A{ 1.0,>0, F} ; B{<1.0,>0, F}",
IntersectResult.FULL_INTER, AnotbResult.FULL_ANOTB), //50
Exact_New(065, "A{ 1.0,>0, F} ; B{ 1.0, 0, T}",
IntersectResult.NEW_1_0_T, AnotbResult.SKETCH_A), //53
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/datasketches/tuple/AnotB.java
Expand Up @@ -257,7 +257,7 @@ public void notB(final org.apache.datasketches.theta.Sketch skB) {
break; //result is already in A
}
case FULL_ANOTB: { //both A and B should have valid entries.
thetaLong_ = min(thetaLong_, skB.getThetaLong());
thetaLong_ = min(thetaLong_, thetaLongB);
final DataArrays<S> daB = getAnotbResultArraysTheta(thetaLong_, curCount_, hashArr_, summaryArr_, skB);
hashArr_ = daB.hashArr;
curCount_ = (hashArr_ == null) ? 0 : hashArr_.length;
Expand Down
31 changes: 1 addition & 30 deletions src/main/java/org/apache/datasketches/tuple/CompactSketch.java
Expand Up @@ -26,7 +26,6 @@

import org.apache.datasketches.ByteArrayUtil;
import org.apache.datasketches.Family;
import org.apache.datasketches.ResizeFactor;
import org.apache.datasketches.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;

Expand Down Expand Up @@ -122,7 +121,7 @@ private enum Flags { IS_BIG_ENDIAN, IS_READ_ONLY, IS_EMPTY, IS_COMPACT, IS_ORDER
} else { // current serial format
offset++; //skip unused byte
final byte flags = mem.getByte(offset++);
offset += 2;
offset += 2; //skip 2 unused bytes
empty_ = (flags & 1 << Flags.IS_EMPTY.ordinal()) > 0;
thetaLong_ = Long.MAX_VALUE;
int count = 0;
Expand Down Expand Up @@ -242,34 +241,6 @@ public byte[] toByteArray() {
return bytes;
}

@SuppressWarnings("unchecked")
CompactSketch<S> trimToTheta(final long thetaLong) {
final QuickSelectSketch<S> qsSk =
new QuickSelectSketch<>(this.getRetainedEntries(), ResizeFactor.X1.lg(), null);
int countOut = 0;
final SketchIterator<S> it = iterator();

while (it.next()) {
final long hash = it.getHash();
final S summary = it.getSummary();
if (hash < thetaLong) {
qsSk.insert(it.getHash(), (S)summary.copy());
countOut++;
}
}

qsSk.setThetaLong(thetaLong);
if (countOut == 0) {
if (thetaLong == Long.MAX_VALUE) {
return new CompactSketch<>(null, null, thetaLong, true);
} else {
return new CompactSketch<>(null, null, thetaLong, false);
}
} else {
return new CompactSketch<>(qsSk.getHashTable(), qsSk.summaryTable_, thetaLong, false);
}
}

@Override
public SketchIterator<S> iterator() {
return new SketchIterator<>(hashArr_, summaryArr_);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/datasketches/tuple/HashTables.java
Expand Up @@ -74,7 +74,7 @@ void fromSketch(final org.apache.datasketches.theta.Sketch sketch, final S summa
}
}

void fromArrays(final long[] hashArr, final S[] summaryArr, final int count) {
private void fromArrays(final long[] hashArr, final S[] summaryArr, final int count) {
count_ = count;
lgTableSize_ = getLgTableSize(count);

Expand Down Expand Up @@ -147,7 +147,7 @@ HashTables<S> getIntersectHashTables(
//Copy the intersecting items from local hashTables_
// sequentially into local matchHashArr_ and matchSummaries_
matchHashArr[matchCount] = hash;
matchSummariesArr[matchCount] = summarySetOps.intersection(summaryTable_[index], (S)summary.copy());
matchSummariesArr[matchCount] = summarySetOps.intersection(summaryTable_[index], summary);
matchCount++;
}
final HashTables<S> resultHT = new HashTables<>();
Expand Down
Expand Up @@ -50,7 +50,7 @@ public class CornerCaseThetaSetOperationsTest {

private enum SkType {
NEW, //{ 1.0, 0, T} Bin: 101 Oct: 05
EXACT, //{ 1.0, >0, F} Bin: 111 Oct: 07, specify only value
EXACT, //{ 1.0, >0, F} Bin: 110 Oct: 06, specify only value
ESTIMATION, //{<1.0, >0, F} Bin: 010 Oct: 02, specify only value
NEW_DEGEN, //{<1.0, 0, T} Bin: 001 Oct: 01, specify only p
RESULT_DEGEN //{<1.0, 0, F} Bin: 000 Oct: 0, specify p, value
Expand Down
Expand Up @@ -60,7 +60,7 @@ public class CornerCaseTupleSetOperationsTest {

private enum SkType {
NEW, //{ 1.0, 0, T} Bin: 101 Oct: 05
EXACT, //{ 1.0, >0, F} Bin: 111 Oct: 07, specify only value
EXACT, //{ 1.0, >0, F} Bin: 110 Oct: 06, specify only value
ESTIMATION, //{<1.0, >0, F} Bin: 010 Oct: 02, specify only value
NEW_DEGEN, //{<1.0, 0, T} Bin: 001 Oct: 01, specify only p
RESULT_DEGEN //{<1.0, 0, F} Bin: 000 Oct: 0, specify p, value
Expand Down

0 comments on commit 8fd253e

Please sign in to comment.