Search in sources :

Example 16 with Memory

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

the class SetOperationTest method checkIllegalSetOpWrap.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkIllegalSetOpWrap() {
    int k = 64;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    for (int i = 0; i < k; i++) {
        //64
        usk1.update(i);
    }
    byte[] byteArray = usk1.toByteArray();
    Memory mem = Memory.wrap(byteArray);
    SetOperation.wrap(mem);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 17 with Memory

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

the class HeapUnionTest method checkSerVer1Handling.

@Test
public void checkSerVer1Handling() {
    //4096
    int lgK = 12;
    int k = 1 << lgK;
    int u1 = 2 * k;
    //smaller exact sketch forces early stop
    int u2 = 1024;
    int totU = u1 + u2;
    UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
    UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
    //2*k
    for (int i = 0; i < u1; i++) usk1.update(i);
    //2*k + 1024 no overlap
    for (int i = u1; i < totU; i++) usk2.update(i);
    WritableMemory skMem1 = WritableMemory.wrap(usk1.compact(true, null).toByteArray());
    WritableMemory skMem2 = WritableMemory.wrap(usk2.compact(true, null).toByteArray());
    Memory v1mem1 = convertSerV3toSerV1(skMem1);
    Memory v1mem2 = convertSerV3toSerV1(skMem2);
    Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
    union.update(v1mem1);
    union.update(v1mem2);
    CompactSketch cOut = union.getResult(true, null);
    assertEquals(cOut.getEstimate(), totU, .05 * k);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 18 with Memory

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

the class HeapUnionTest method checkEmptySerVer2and3.

@Test
public //where the granted mem is larger than required
void checkEmptySerVer2and3() {
    UpdateSketch usk1 = UpdateSketch.builder().build();
    CompactSketch usk1c = usk1.compact(true, null);
    byte[] skArr = usk1c.toByteArray();
    byte[] skArr2 = Arrays.copyOf(skArr, skArr.length * 2);
    WritableMemory v3mem1 = WritableMemory.wrap(skArr2);
    Union union = SetOperation.builder().buildUnion();
    union.update(v3mem1);
    Memory v2mem1 = convertSerV3toSerV2(v3mem1);
    WritableMemory v2mem2 = WritableMemory.wrap(new byte[16]);
    v2mem1.copyTo(0, v2mem2, 0, 8);
    union = SetOperation.builder().buildUnion();
    union.update(v2mem2);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 19 with Memory

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

the class ReadOnlyMemoryTest method heapifyIntersection.

@Test
public void heapifyIntersection() {
    UpdateSketch us1 = UpdateSketch.builder().build();
    us1.update(1);
    us1.update(2);
    UpdateSketch us2 = UpdateSketch.builder().build();
    us2.update(2);
    us2.update(3);
    Intersection i1 = SetOperation.builder().buildIntersection();
    i1.update(us1);
    i1.update(us2);
    Memory mem = Memory.wrap(ByteBuffer.wrap(i1.toByteArray()).asReadOnlyBuffer());
    Intersection i2 = (Intersection) SetOperation.heapify(mem);
    i2.update(us1);
    Assert.assertEquals(i2.getResult().getEstimate(), 1.0);
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Example 20 with Memory

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

the class ReadOnlyMemoryTest method heapifyCompactOrderedSketch.

@Test
public void heapifyCompactOrderedSketch() {
    UpdateSketch updateSketch = UpdateSketch.builder().build();
    updateSketch.update(1);
    Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact().toByteArray()).asReadOnlyBuffer());
    Sketch sketch = Sketch.heapify(mem);
    assertEquals(sketch.getEstimate(), 1.0);
}
Also used : Memory(com.yahoo.memory.Memory) Test(org.testng.annotations.Test)

Aggregations

Memory (com.yahoo.memory.Memory)141 Test (org.testng.annotations.Test)121 WritableMemory (com.yahoo.memory.WritableMemory)111 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)10 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)10 SketchesReadOnlyException (com.yahoo.sketches.SketchesReadOnlyException)6 MemoryRegion (com.yahoo.memory.MemoryRegion)2 NativeMemory (com.yahoo.memory.NativeMemory)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 CompactSketch.createCompactSketch (com.yahoo.sketches.theta.CompactSketch.createCompactSketch)1 Union (com.yahoo.sketches.theta.Union)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1