Search in sources :

Example 6 with DefaultMemoryRequestServer

use of org.apache.datasketches.memory.DefaultMemoryRequestServer in project sketches-core by DataSketches.

the class DoublesSketchTest method directSketchShouldMoveOntoHeapEventually2.

@Test
public void directSketchShouldMoveOntoHeapEventually2() {
    int i = 0;
    try (WritableHandle wdh = WritableMemory.allocateDirect(50, ByteOrder.LITTLE_ENDIAN, new DefaultMemoryRequestServer())) {
        WritableMemory mem = wdh.getWritable();
        UpdateDoublesSketch sketch = DoublesSketch.builder().build(mem);
        Assert.assertTrue(sketch.isSameResource(mem));
        for (; i < 1000; i++) {
            if (sketch.isSameResource(mem)) {
                sketch.update(i);
            } else {
                // println("MOVED OUT at i = " + i);
                break;
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WritableHandle(org.apache.datasketches.memory.WritableHandle) WritableMemory(org.apache.datasketches.memory.WritableMemory) DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) Test(org.testng.annotations.Test)

Example 7 with DefaultMemoryRequestServer

use of org.apache.datasketches.memory.DefaultMemoryRequestServer in project sketches-core by DataSketches.

the class DirectAuxHashMapTest method checkGrow.

@Test
public void checkGrow() {
    int lgConfigK = 4;
    TgtHllType tgtHllType = TgtHllType.HLL_4;
    // put lgConfigK == 4 into HLL mode
    int n = 8;
    int bytes = HllSketch.getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType);
    HllSketch hllSketch;
    try (WritableHandle handle = WritableMemory.allocateDirect(bytes, ByteOrder.nativeOrder(), new DefaultMemoryRequestServer())) {
        WritableMemory wmem = handle.getWritable();
        hllSketch = new HllSketch(lgConfigK, tgtHllType, wmem);
        for (int i = 0; i < n; i++) {
            hllSketch.update(i);
        }
        // mock extreme values
        hllSketch.couponUpdate(HllUtil.pair(7, 15));
        hllSketch.couponUpdate(HllUtil.pair(8, 15));
        hllSketch.couponUpdate(HllUtil.pair(9, 15));
        // println(hllSketch.toString(true, true, true, true));
        DirectHllArray dha = (DirectHllArray) hllSketch.hllSketchImpl;
        assertEquals(dha.getAuxHashMap().getLgAuxArrInts(), 2);
        assertTrue(hllSketch.isMemory());
        assertTrue(hllSketch.isOffHeap());
        assertTrue(hllSketch.isSameResource(wmem));
        // Check heapify
        byte[] byteArray = hllSketch.toCompactByteArray();
        HllSketch hllSketch2 = HllSketch.heapify(byteArray);
        HllArray ha = (HllArray) hllSketch2.hllSketchImpl;
        assertEquals(ha.getAuxHashMap().getLgAuxArrInts(), 2);
        assertEquals(ha.getAuxHashMap().getAuxCount(), 3);
        // Check wrap
        byteArray = hllSketch.toUpdatableByteArray();
        WritableMemory wmem2 = WritableMemory.writableWrap(byteArray);
        hllSketch2 = HllSketch.writableWrap(wmem2);
        // println(hllSketch2.toString(true, true, true, true));
        DirectHllArray dha2 = (DirectHllArray) hllSketch2.hllSketchImpl;
        assertEquals(dha2.getAuxHashMap().getLgAuxArrInts(), 2);
        assertEquals(dha2.getAuxHashMap().getAuxCount(), 3);
        // Check grow to on-heap
        // puts it over the edge, must grow
        hllSketch.couponUpdate(HllUtil.pair(10, 15));
        // println(hllSketch.toString(true, true, true, true));
        dha = (DirectHllArray) hllSketch.hllSketchImpl;
        assertEquals(dha.getAuxHashMap().getLgAuxArrInts(), 3);
        assertEquals(dha.getAuxHashMap().getAuxCount(), 4);
        assertTrue(hllSketch.isMemory());
        assertFalse(hllSketch.isOffHeap());
        assertFalse(hllSketch.isSameResource(wmem));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : WritableHandle(org.apache.datasketches.memory.WritableHandle) WritableMemory(org.apache.datasketches.memory.WritableMemory) DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) SketchesStateException(org.apache.datasketches.SketchesStateException) Test(org.testng.annotations.Test)

Example 8 with DefaultMemoryRequestServer

use of org.apache.datasketches.memory.DefaultMemoryRequestServer in project sketches-core by DataSketches.

the class SetOperationTest method checkBuilder2.

@Test
public void checkBuilder2() {
    final SetOperationBuilder bldr = SetOperation.builder();
    final long seed = 12345L;
    bldr.setSeed(seed);
    assertEquals(bldr.getSeed(), seed);
    final float p = (float) 0.5;
    bldr.setP(p);
    assertEquals(bldr.getP(), p);
    final ResizeFactor rf = ResizeFactor.X4;
    bldr.setResizeFactor(rf);
    assertEquals(bldr.getResizeFactor(), rf);
    final int lgK = 10;
    final int k = 1 << lgK;
    bldr.setNominalEntries(k);
    assertEquals(bldr.getLgNominalEntries(), lgK);
    final MemoryRequestServer mrs = new DefaultMemoryRequestServer();
    bldr.setMemoryRequestServer(mrs);
    assertEquals(bldr.getMemoryRequestServer(), mrs);
    println(bldr.toString());
}
Also used : DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) ResizeFactor(org.apache.datasketches.ResizeFactor) DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) MemoryRequestServer(org.apache.datasketches.memory.MemoryRequestServer) Test(org.testng.annotations.Test)

Example 9 with DefaultMemoryRequestServer

use of org.apache.datasketches.memory.DefaultMemoryRequestServer in project sketches-core by DataSketches.

the class UpdateSketchTest method checkBuilder.

@Test
public void checkBuilder() {
    UpdateSketchBuilder bldr = UpdateSketch.builder();
    long seed = 12345L;
    bldr.setSeed(seed);
    assertEquals(bldr.getSeed(), seed);
    float p = (float) 0.5;
    bldr.setP(p);
    assertEquals(bldr.getP(), p);
    ResizeFactor rf = ResizeFactor.X4;
    bldr.setResizeFactor(rf);
    assertEquals(bldr.getResizeFactor(), rf);
    Family fam = Family.ALPHA;
    bldr.setFamily(fam);
    assertEquals(bldr.getFamily(), fam);
    int lgK = 10;
    int k = 1 << lgK;
    bldr.setNominalEntries(k);
    assertEquals(bldr.getLgNominalEntries(), lgK);
    MemoryRequestServer mrs = new DefaultMemoryRequestServer();
    bldr.setMemoryRequestServer(mrs);
    assertEquals(bldr.getMemoryRequestServer(), mrs);
    println(bldr.toString());
}
Also used : Family(org.apache.datasketches.Family) DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) ResizeFactor(org.apache.datasketches.ResizeFactor) PreambleUtil.insertLgResizeFactor(org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor) DefaultMemoryRequestServer(org.apache.datasketches.memory.DefaultMemoryRequestServer) MemoryRequestServer(org.apache.datasketches.memory.MemoryRequestServer) Test(org.testng.annotations.Test)

Aggregations

DefaultMemoryRequestServer (org.apache.datasketches.memory.DefaultMemoryRequestServer)9 Test (org.testng.annotations.Test)9 WritableHandle (org.apache.datasketches.memory.WritableHandle)7 WritableMemory (org.apache.datasketches.memory.WritableMemory)7 ResizeFactor (org.apache.datasketches.ResizeFactor)2 MemoryRequestServer (org.apache.datasketches.memory.MemoryRequestServer)2 Family (org.apache.datasketches.Family)1 SketchesStateException (org.apache.datasketches.SketchesStateException)1 Memory (org.apache.datasketches.memory.Memory)1 PreambleUtil.insertLgResizeFactor (org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor)1