Search in sources :

Example 11 with Memory

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

the class HeapQuickSelectSketchTest method checkMinReqBytes.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMinReqBytes() {
    int k = 16;
    UpdateSketch s1 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
    for (int i = 0; i < 4 * k; i++) {
        s1.update(i);
    }
    byte[] byteArray = s1.toByteArray();
    byte[] badBytes = Arrays.copyOfRange(byteArray, 0, 24);
    Memory mem = Memory.wrap(badBytes);
    Sketch.heapify(mem);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 12 with Memory

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

the class ReadOnlyMemoryTest method wrapCompactOrderedSketch.

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

Example 13 with Memory

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

the class ReadOnlyMemoryTest method wrapIntersection.

@Test
public void wrapIntersection() {
    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.wrap(mem);
    Assert.assertEquals(i2.getResult().getEstimate(), 1.0);
    boolean thrown = false;
    try {
        i2.update(us1);
    } catch (SketchesReadOnlyException e) {
        thrown = true;
    }
    Assert.assertTrue(thrown);
}
Also used : Memory(com.yahoo.memory.Memory) SketchesReadOnlyException(com.yahoo.sketches.SketchesReadOnlyException) Test(org.testng.annotations.Test)

Example 14 with Memory

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

the class SetOperationTest method checkIsSameResource.

@Test
public void checkIsSameResource() {
    int k = 16;
    WritableMemory mem = WritableMemory.wrap(new byte[(k * 16) + 32]);
    Memory cmem = Memory.wrap(new byte[8]);
    Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(mem);
    assertTrue(union.isSameResource(mem));
    assertFalse(union.isSameResource(cmem));
    Intersection inter = Sketches.setOperationBuilder().buildIntersection(mem);
    assertTrue(inter.isSameResource(mem));
    assertFalse(inter.isSameResource(cmem));
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 15 with Memory

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

the class SetOperationTest method checkIllegalSetOpHeapify.

@Test(expectedExceptions = SketchesArgumentException.class)
public void checkIllegalSetOpHeapify() {
    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.heapify(mem);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) 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