use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchesTest method getCompactSketch.
private static Memory getCompactSketch(int k, int from, int to) {
UpdateSketch sk1 = updateSketchBuilder().setNominalEntries(k).build();
for (int i = from; i < to; i++) sk1.update(i);
CompactSketch csk = sk1.compact(true, null);
byte[] sk1bytes = csk.toByteArray();
Memory mem = Memory.wrap(sk1bytes);
return mem;
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DoublesUnionBuilderTest method checkBuilds.
@Test
public void checkBuilds() {
UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
for (int i = 0; i < 1000; i++) {
qs1.update(i);
}
int bytes = qs1.getCompactStorageBytes();
WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]);
qs1.putMemory(dstMem);
Memory srcMem = dstMem;
DoublesUnionBuilder bldr = new DoublesUnionBuilder();
bldr.setMaxK(128);
//virgin union
DoublesUnion union = bldr.build();
union = DoublesUnionBuilder.heapify(srcMem);
DoublesSketch qs2 = union.getResult();
assertEquals(qs1.getCompactStorageBytes(), qs2.getCompactStorageBytes());
union = DoublesUnionBuilder.heapify(qs2);
DoublesSketch qs3 = union.getResult();
assertEquals(qs2.getCompactStorageBytes(), qs3.getCompactStorageBytes());
assertFalse(qs2 == qs3);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DoublesUnionBuilderTest method checkDeprecated1.
@SuppressWarnings("deprecation")
@Test
public void checkDeprecated1() {
UpdateDoublesSketch qs1 = DoublesSketch.builder().build();
for (int i = 0; i < 1000; i++) qs1.update(i);
int bytes = qs1.getCompactStorageBytes();
WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]);
qs1.putMemory(dstMem);
Memory srcMem = dstMem;
DoublesUnionBuilder bldr = new DoublesUnionBuilder();
bldr.setMaxK(128);
//virgin union
DoublesUnion union = bldr.build();
//heapify
union = DoublesUnionBuilder.heapify(srcMem);
DoublesSketch qs2 = union.getResult();
assertEquals(qs1.getCompactStorageBytes(), qs2.getCompactStorageBytes());
assertEquals(qs1.getUpdatableStorageBytes(), qs2.getUpdatableStorageBytes());
//heapify again
union = DoublesUnionBuilder.heapify(qs2);
DoublesSketch qs3 = union.getResult();
assertEquals(qs2.getCompactStorageBytes(), qs3.getCompactStorageBytes());
assertEquals(qs2.getUpdatableStorageBytes(), qs3.getUpdatableStorageBytes());
//different objects
assertFalse(qs2 == qs3);
DoublesUnion union2 = DoublesUnionBuilder.copyBuild(qs3);
DoublesSketch qs4 = union2.getResult();
assertEquals(qs3.getCompactStorageBytes(), qs4.getCompactStorageBytes());
assertEquals(qs3.getUpdatableStorageBytes(), qs4.getUpdatableStorageBytes());
//different objects
assertFalse(qs3 == qs4);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkUnionQuantiles.
@Test
public void checkUnionQuantiles() {
final int k = 128;
final int n1 = k * 13;
final int n2 = k * 8 + k / 2;
final int n = n1 + n2;
// assuming k = 128
final double errorTolerance = 0.0175 * n;
final UpdateDoublesSketch sketch1 = buildAndLoadQS(k, n1);
final CompactDoublesSketch sketch2 = buildAndLoadQS(k, n2, n1).compact();
//virgin 256
final DoublesUnion union = DoublesUnion.builder().setMaxK(256).build();
union.update(sketch2);
union.update(sketch1);
final Memory mem = Memory.wrap(union.getResult().toByteArray(true));
final DoublesSketch result = DoublesSketch.wrap(mem);
assertEquals(result.getN(), n1 + n2);
assertEquals(result.getK(), k);
for (double fraction = 0.05; fraction < 1.0; fraction += 0.05) {
assertEquals(result.getQuantile(fraction), fraction * n, errorTolerance);
}
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkUpdateMemory.
@Test
public void checkUpdateMemory() {
DoublesSketch qs1 = buildAndLoadQS(256, 1000);
int bytes = qs1.getCompactStorageBytes();
WritableMemory dstMem = WritableMemory.wrap(new byte[bytes]);
qs1.putMemory(dstMem);
Memory srcMem = dstMem;
//virgin
DoublesUnion union = DoublesUnion.builder().build();
union.update(srcMem);
for (int i = 1000; i < 2000; i++) union.update(i);
DoublesSketch qs2 = union.getResult();
assertEquals(qs2.getMaxValue(), 1999, 0.0);
String s = union.toString();
//enable printing to see
println(s);
//sets to null
union.reset();
}
Aggregations