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);
}
}
}
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());
}
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());
}
Aggregations