Search in sources :

Example 6 with AnotB

use of org.apache.datasketches.tuple.AnotB in project sketches-core by DataSketches.

the class AdoubleAnotBTest method aNotBExactEmpty.

@Test
public void aNotBExactEmpty() {
    final UpdatableSketch<Double, DoubleSummary> sketchA = buildUpdatableTuple();
    sketchA.update(1, 1.0);
    sketchA.update(2, 1.0);
    final UpdatableSketch<Double, DoubleSummary> sketchB = buildUpdatableTuple();
    final UpdateSketch skThetaB = buildUpdateTheta();
    final AnotB<DoubleSummary> aNotB = new AnotB<>();
    results.set(2, false, 2.0, 0.0, 1.0);
    threeMethodsWithTheta(aNotB, sketchA, sketchB, skThetaB, results);
    // same thing, but compact sketches
    threeMethodsWithTheta(aNotB, sketchA.compact(), sketchB.compact(), skThetaB.compact(), results);
}
Also used : AnotB(org.apache.datasketches.tuple.AnotB) UpdateSketch(org.apache.datasketches.theta.UpdateSketch) Test(org.testng.annotations.Test)

Example 7 with AnotB

use of org.apache.datasketches.tuple.AnotB in project sketches-core by DataSketches.

the class ArrayOfStringsSketchTest method checkSketch.

@SuppressWarnings("deprecation")
@Test
public void checkSketch() {
    ArrayOfStringsSketch sketch1 = new ArrayOfStringsSketch();
    String[][] strArrArr = { { "a", "b" }, { "c", "d" }, { "e", "f" } };
    int len = strArrArr.length;
    for (int i = 0; i < len; i++) {
        sketch1.update(strArrArr[i], strArrArr[i]);
    }
    // insert duplicate
    sketch1.update(strArrArr[0], strArrArr[0]);
    // printSummaries(sketch1.iterator());
    byte[] array = sketch1.toByteArray();
    WritableMemory wmem = WritableMemory.writableWrap(array);
    ArrayOfStringsSketch sketch2 = new ArrayOfStringsSketch(wmem);
    // printSummaries(sketch2.iterator());
    checkSummaries(sketch2, sketch2);
    String[] strArr3 = { "g", "h" };
    sketch2.update(strArr3, strArr3);
    Union<ArrayOfStringsSummary> union = new Union<>(new ArrayOfStringsSummarySetOperations());
    union.union(sketch1);
    union.union(sketch2);
    CompactSketch<ArrayOfStringsSummary> csk = union.getResult();
    // printSummaries(csk.iterator());
    assertEquals(csk.getRetainedEntries(), 4);
    Intersection<ArrayOfStringsSummary> inter = new Intersection<>(new ArrayOfStringsSummarySetOperations());
    inter.intersect(sketch1);
    inter.intersect(sketch2);
    csk = inter.getResult();
    assertEquals(csk.getRetainedEntries(), 3);
    AnotB<ArrayOfStringsSummary> aNotB = new AnotB<>();
    aNotB.setA(sketch2);
    aNotB.notB(sketch1);
    csk = aNotB.getResult(true);
    assertEquals(csk.getRetainedEntries(), 1);
}
Also used : Intersection(org.apache.datasketches.tuple.Intersection) Union(org.apache.datasketches.tuple.Union) AnotB(org.apache.datasketches.tuple.AnotB) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

AnotB (org.apache.datasketches.tuple.AnotB)7 Test (org.testng.annotations.Test)7 UpdateSketch (org.apache.datasketches.theta.UpdateSketch)6 WritableMemory (org.apache.datasketches.memory.WritableMemory)1 Intersection (org.apache.datasketches.tuple.Intersection)1 Union (org.apache.datasketches.tuple.Union)1