Search in sources :

Example 86 with WritableMemory

use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.

the class DirectIntersectionTest method check2ndCallAfterEmpty.

@Test
public void check2ndCallAfterEmpty() {
    int lgK = 9;
    int k = 1 << lgK;
    Intersection inter;
    UpdateSketch sk1, sk2;
    CompactSketch comp1;
    double est;
    int memBytes = getMaxIntersectionBytes(k);
    byte[] memArr = new byte[memBytes];
    WritableMemory iMem = WritableMemory.wrap(memArr);
    //1st call = empty
    //empty
    sk1 = UpdateSketch.builder().build();
    inter = SetOperation.builder().buildIntersection(iMem);
    inter.update(sk1);
    //2nd call = null
    inter.update(null);
    comp1 = inter.getResult(false, null);
    est = comp1.getEstimate();
    assertEquals(est, 0.0, 0.0);
    println("Est: " + est);
    //1st call = empty
    //empty
    sk1 = UpdateSketch.builder().build();
    inter = SetOperation.builder().buildIntersection(iMem);
    inter.update(sk1);
    //2nd call = empty
    //empty
    sk2 = UpdateSketch.builder().build();
    inter.update(sk2);
    comp1 = inter.getResult(false, null);
    est = comp1.getEstimate();
    assertEquals(est, 0.0, 0.0);
    println("Est: " + est);
    //1st call = empty
    //empty
    sk1 = UpdateSketch.builder().build();
    inter = SetOperation.builder().buildIntersection(iMem);
    inter.update(sk1);
    //2nd call = valid and not empty
    sk2 = UpdateSketch.builder().build();
    sk2.update(1);
    inter.update(sk2);
    comp1 = inter.getResult(false, null);
    est = comp1.getEstimate();
    assertEquals(est, 0.0, 0.0);
    println("Est: " + est);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 87 with WritableMemory

use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.

the class DirectIntersectionTest method checkExceptionMinSize.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkExceptionMinSize() {
    int k = 16;
    WritableMemory mem = WritableMemory.wrap(new byte[k * 8 + PREBYTES]);
    IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 88 with WritableMemory

use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.

the class DirectIntersectionTest method checkBadPreambleLongs.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadPreambleLongs() {
    int k = 32;
    int memBytes = getMaxIntersectionBytes(k);
    byte[] memArr = new byte[memBytes];
    WritableMemory iMem = WritableMemory.wrap(memArr);
    //virgin
    Intersection inter1 = SetOperation.builder().buildIntersection(iMem);
    byte[] byteArray = inter1.toByteArray();
    WritableMemory mem = WritableMemory.wrap(byteArray);
    //corrupt:
    //RF not used = 0
    mem.putByte(PREAMBLE_LONGS_BYTE, (byte) 2);
    Sketches.wrapIntersection(mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 89 with WritableMemory

use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.

the class DoublesUnionImplTest method checkUnion5.

@Test
public void checkUnion5() {
    //Union is direct, valid and with larger K than valid input
    int k2 = 4;
    //8
    int n2 = 2 * k2;
    //big enough
    int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);
    WritableMemory skMem = WritableMemory.wrap(new byte[bytes]);
    DoublesSketch.builder().setK(256).build(skMem);
    DoublesUnion union = DoublesUnionImpl.heapifyInstance(skMem);
    assertEquals(union.getResult().getN(), 0);
    assertEquals(union.getMaxK(), 256);
    assertEquals(union.getEffectiveK(), 256);
    DoublesSketch result = union.getResult();
    assertEquals(result.getK(), 256);
    DoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17);
    union.update(sketchIn2);
    println("\nFinal" + union.getResult().toString(true, true));
    assertEquals(union.getResult().getN(), n2);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 90 with WritableMemory

use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.

the class DoublesUnionImplTest method checkUnion3.

@Test
public void checkUnion3() {
    //Union is direct, empty and with larger K than valid input
    int k1 = 128;
    int n1 = 2 * k1;
    int k2 = 256;
    int n2 = 2000;
    DoublesSketch sketchIn1 = buildAndLoadQS(k1, n1);
    //just for size
    int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n2);
    WritableMemory mem = WritableMemory.wrap(new byte[bytes]);
    //virgin 256
    DoublesUnion union = DoublesUnion.builder().setMaxK(k2).build(mem);
    union.update(sketchIn1);
    assertEquals(union.getMaxK(), k2);
    assertEquals(union.getEffectiveK(), k1);
    DoublesSketch result = union.getResult();
    assertEquals(result.getMaxValue(), n1, 0.0);
    assertEquals(result.getMinValue(), 1.0, 0.0);
    assertEquals(result.getK(), k1);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

WritableMemory (com.yahoo.memory.WritableMemory)264 Test (org.testng.annotations.Test)210 Memory (com.yahoo.memory.Memory)34 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)15 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)6 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)5 MemoryRequestServer (com.yahoo.memory.MemoryRequestServer)2 ArrayOfDoublesSerDe (com.yahoo.sketches.ArrayOfDoublesSerDe)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 PreambleUtil.extractTgtHllType (com.yahoo.sketches.hll.PreambleUtil.extractTgtHllType)2 ResizeFactor (com.yahoo.sketches.ResizeFactor)1 PreambleUtil.extractCurMode (com.yahoo.sketches.hll.PreambleUtil.extractCurMode)1 PreambleUtil.insertTgtHllType (com.yahoo.sketches.hll.PreambleUtil.insertTgtHllType)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ByteBuffer (java.nio.ByteBuffer)1