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