use of org.apache.datasketches.memory.WritableMemory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkUnion5.
@Test
public void checkUnion5() {
// Union is direct, valid and with larger K than valid input
final int k2 = 4;
// 8
final int n2 = 2 * k2;
// big enough
final int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);
final WritableMemory skMem = WritableMemory.writableWrap(new byte[bytes]);
DoublesSketch.builder().setK(256).build(skMem);
final DoublesUnion union = DoublesUnionImpl.heapifyInstance(skMem);
assertEquals(union.getResult().getN(), 0);
assertEquals(union.getMaxK(), 256);
assertEquals(union.getEffectiveK(), 256);
final DoublesSketch result = union.getResult();
assertEquals(result.getK(), 256);
final DoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17);
union.update(sketchIn2);
println("\nFinal" + union.getResult().toString(true, true));
assertEquals(union.getResult().getN(), n2);
}
use of org.apache.datasketches.memory.WritableMemory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method isSameResourceDirect.
@Test
public void isSameResourceDirect() {
WritableMemory mem1 = WritableMemory.writableWrap(new byte[1000000]);
DoublesUnion union = DoublesUnion.builder().build(mem1);
Assert.assertTrue(union.isSameResource(mem1));
WritableMemory mem2 = WritableMemory.writableWrap(new byte[1000000]);
Assert.assertFalse(union.isSameResource(mem2));
}
use of org.apache.datasketches.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.writableWrap(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 org.apache.datasketches.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.writableWrap(new byte[bytes - 1]);
qs1.putMemory(dstMem);
}
use of org.apache.datasketches.memory.WritableMemory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method testDownSampling3withMem.
//
@Test
public void testDownSampling3withMem() {
int k1 = 8;
int k2 = 2;
int n = 50;
UpdateDoublesSketch sketch1 = DoublesSketch.builder().setK(k1).build();
UpdateDoublesSketch sketch2 = DoublesSketch.builder().setK(k2).build();
DoublesSketch downSketch;
int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n);
WritableMemory mem = WritableMemory.writableWrap(new byte[bytes]);
for (int i = 0; i < n; i++) {
sketch1.update(i);
sketch2.update(i);
downSketch = sketch1.downSample(sketch1, k2, mem);
assertTrue(sameStructurePredicate(sketch2, downSketch));
}
}
Aggregations