Search in sources :

Example 71 with WritableMemory

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

the class DirectIntersectionTest method checkExactIntersectionNoOverlap.

@Test
public void checkExactIntersectionNoOverlap() {
    int lgK = 9;
    int k = 1 << lgK;
    Intersection inter;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
    for (int i = 0; i < k / 2; i++) usk1.update(i);
    for (int i = k / 2; i < k; i++) usk2.update(i);
    int memBytes = getMaxIntersectionBytes(k);
    byte[] memArr = new byte[memBytes];
    WritableMemory iMem = WritableMemory.wrap(memArr);
    inter = SetOperation.builder().buildIntersection(iMem);
    inter.update(usk1);
    inter.update(usk2);
    CompactSketch rsk1;
    boolean ordered = true;
    assertTrue(inter.hasResult());
    rsk1 = inter.getResult(!ordered, null);
    assertEquals(rsk1.getEstimate(), 0.0);
    rsk1 = inter.getResult(ordered, null);
    assertEquals(rsk1.getEstimate(), 0.0);
    boolean compact = true;
    int bytes = rsk1.getCurrentBytes(compact);
    byte[] byteArray = new byte[bytes];
    WritableMemory mem = WritableMemory.wrap(byteArray);
    rsk1 = inter.getResult(!ordered, mem);
    assertEquals(rsk1.getEstimate(), 0.0);
    //executed twice to fully exercise the internal state machine
    rsk1 = inter.getResult(ordered, mem);
    assertEquals(rsk1.getEstimate(), 0.0);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 72 with WritableMemory

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

the class DirectIntersectionTest method checkWrapNullEmpty.

@Test
public void checkWrapNullEmpty() {
    int lgK = 5;
    int k = 1 << lgK;
    Intersection inter1, inter2;
    int memBytes = getMaxIntersectionBytes(k);
    byte[] memArr = new byte[memBytes];
    WritableMemory iMem = WritableMemory.wrap(memArr);
    //virgin
    inter1 = SetOperation.builder().buildIntersection(iMem);
    inter2 = Sketches.wrapIntersection(iMem);
    //both in virgin state, empty = false
    assertFalse(inter1.hasResult());
    assertFalse(inter2.hasResult());
    //A virgin intersection intersected with null => empty = true;
    inter1.update(null);
    inter2 = Sketches.wrapIntersection(iMem);
    assertTrue(inter1.hasResult());
    assertTrue(inter2.hasResult());
    CompactSketch comp = inter2.getResult(true, null);
    assertEquals(comp.getRetainedEntries(false), 0);
    assertTrue(comp.isEmpty());
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 73 with WritableMemory

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

the class DirectIntersectionTest method checkFamilyID.

@Test(expectedExceptions = ClassCastException.class)
public void checkFamilyID() {
    int k = 32;
    Union union;
    union = SetOperation.builder().setNominalEntries(k).buildUnion();
    byte[] byteArray = union.toByteArray();
    WritableMemory mem = WritableMemory.wrap(byteArray);
    Sketches.wrapIntersection(mem);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 74 with WritableMemory

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

the class DirectIntersectionTest method checkFamily.

@Test
public void checkFamily() {
    //cheap trick
    int k = 16;
    WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + PREBYTES]);
    IntersectionImplR impl = IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
    assertEquals(impl.getFamily(), Family.INTERSECTION);
}
Also used : WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 75 with WritableMemory

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

the class DirectIntersectionTest method checkExceptions2.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkExceptions2() {
    int k = 16;
    WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + PREBYTES]);
    IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
    //mem now has non-empty intersection
    //corrupt empty and CurCount
    mem.setBits(PreambleUtil.FLAGS_BYTE, (byte) PreambleUtil.EMPTY_FLAG_MASK);
    mem.putInt(PreambleUtil.RETAINED_ENTRIES_INT, 2);
    IntersectionImplR.wrapInstance(mem, DEFAULT_UPDATE_SEED);
}
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