use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method testIt.
//Himanshu's case
@Test
public void testIt() {
java.nio.ByteBuffer bb = java.nio.ByteBuffer.allocate(1 << 20);
WritableMemory mem = WritableMemory.wrap(bb);
int k = 1024;
DoublesSketch qsk = new DoublesSketchBuilder().setK(k).build();
DoublesUnion u1 = DoublesUnionBuilder.heapify(qsk);
u1.getResult().putMemory(mem);
DoublesUnion u2 = DoublesUnionBuilder.heapify(mem);
DoublesSketch qsk2 = u2.getResult();
assertTrue(qsk2.isEmpty());
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkPutMemory.
@Test
public void checkPutMemory() {
//k = 128
UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
for (int i = 0; i < 1000; i++) qs1.update(i);
int bytes = qs1.getUpdatableStorageBytes();
WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]);
qs1.putMemory(dstMem, false);
Memory srcMem = dstMem;
DoublesSketch qs2 = DoublesSketch.heapify(srcMem);
assertEquals(qs1.getMinValue(), qs2.getMinValue(), 0.0);
assertEquals(qs1.getMaxValue(), qs2.getMaxValue(), 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkPutMemoryTooSmall.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkPutMemoryTooSmall() {
//k = 128
UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
for (int i = 0; i < 1000; i++) qs1.update(i);
int bytes = qs1.getCompactStorageBytes();
//too small
WritableMemory dstMem = WritableMemory.wrap(new byte[bytes - 1]);
qs1.putMemory(dstMem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class CompactSketchTest method checkMemTooSmall.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMemTooSmall() {
int k = 512;
int u = k;
boolean compact = true;
boolean ordered = false;
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build();
for (int i = 0; i < u; i++) usk.update(i);
int bytes = usk.getCurrentBytes(compact);
//too small
byte[] byteArray = new byte[bytes - 8];
WritableMemory mem = WritableMemory.wrap(byteArray);
usk.compact(ordered, mem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkWrap.
@Test
public void checkWrap() {
int lgK = 9;
int k = 1 << lgK;
Intersection inter, inter2, inter3;
UpdateSketch sk1, sk2;
CompactSketch resultComp1, resultComp2;
double est, est2;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr1 = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr1);
//1st call = valid
sk1 = UpdateSketch.builder().setNominalEntries(k).build();
//est mode
for (int i = 0; i < 2 * k; i++) sk1.update(i);
CompactSketch compSkIn1 = sk1.compact(true, null);
println("compSkIn1: " + compSkIn1.getEstimate());
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(compSkIn1);
byte[] memArr2 = inter.toByteArray();
WritableMemory srcMem = WritableMemory.wrap(memArr2);
inter2 = Sketches.wrapIntersection(srcMem);
//2nd call = valid intersecting
sk2 = UpdateSketch.builder().setNominalEntries(k).build();
//est mode
for (int i = 0; i < 2 * k; i++) sk2.update(i);
CompactSketch compSkIn2 = sk2.compact(true, null);
println("sk2: " + compSkIn2.getEstimate());
inter2.update(compSkIn2);
resultComp1 = inter2.getResult(false, null);
est = resultComp1.getEstimate();
assertTrue(est > k);
println("Est: " + est);
byte[] memArr3 = inter2.toByteArray();
WritableMemory srcMem2 = WritableMemory.wrap(memArr3);
inter3 = Sketches.wrapIntersection(srcMem2);
resultComp2 = inter3.getResult(false, null);
est2 = resultComp2.getEstimate();
println("Est2: " + est2);
inter.reset();
inter2.reset();
inter3.reset();
}
Aggregations