Search in sources :

Example 1 with MemoryRequestServer

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

the class DirectAuxHashMap method grow.

private static final void grow(final DirectHllArray host, final int oldLgAuxArrInts) {
    if (host.wmem == null) {
        noWriteAccess();
    }
    final int oldAuxArrInts = 1 << oldLgAuxArrInts;
    // buffer old aux data
    final int[] oldIntArray = new int[oldAuxArrInts];
    host.wmem.getIntArray(host.auxStart, oldIntArray, 0, oldAuxArrInts);
    // update LgArr field
    insertLgArr(host.wmem, oldLgAuxArrInts + 1);
    final long newAuxBytes = oldAuxArrInts << 3;
    final long requestBytes = host.auxStart + newAuxBytes;
    final long oldCapBytes = host.wmem.getCapacity();
    if (requestBytes > oldCapBytes) {
        final MemoryRequestServer svr = host.wmem.getMemoryRequestServer();
        final WritableMemory newWmem = svr.request(host.wmem, requestBytes);
        host.wmem.copyTo(0, newWmem, 0, host.auxStart);
        // clear space for new aux data
        newWmem.clear(host.auxStart, newAuxBytes);
        // old host.wmem is now invalid
        svr.requestClose(host.wmem, newWmem);
        host.updateMemory(newWmem);
    }
    // rehash into larger aux array
    final int configKmask = (1 << host.lgConfigK) - 1;
    for (int i = 0; i < oldAuxArrInts; i++) {
        final int fetched = oldIntArray[i];
        if (fetched != EMPTY) {
            // find empty in new array
            final int index = find(host, fetched & configKmask);
            host.wmem.putInt(host.auxStart + (~index << 2), fetched);
        }
    }
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) MemoryRequestServer(org.apache.datasketches.memory.MemoryRequestServer)

Example 2 with MemoryRequestServer

use of org.apache.datasketches.memory.MemoryRequestServer 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 3 with MemoryRequestServer

use of org.apache.datasketches.memory.MemoryRequestServer 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

MemoryRequestServer (org.apache.datasketches.memory.MemoryRequestServer)3 ResizeFactor (org.apache.datasketches.ResizeFactor)2 DefaultMemoryRequestServer (org.apache.datasketches.memory.DefaultMemoryRequestServer)2 Test (org.testng.annotations.Test)2 Family (org.apache.datasketches.Family)1 WritableMemory (org.apache.datasketches.memory.WritableMemory)1 PreambleUtil.insertLgResizeFactor (org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor)1