use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapCompactDoublesSketchTest method heapifyFromUpdateSketch.
@Test
public void heapifyFromUpdateSketch() {
final int k = 4;
final int n = 45;
final UpdateDoublesSketch qs = buildAndLoadQS(k, n);
final byte[] qsBytes = qs.toByteArray();
final Memory qsMem = Memory.wrap(qsBytes);
final HeapCompactDoublesSketch compactQs = HeapCompactDoublesSketch.heapifyInstance(qsMem);
DoublesSketchTest.testSketchEquality(qs, compactQs);
assertNull(compactQs.getMemory());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapCompactDoublesSketchTest method heapifyFromCompactSketch.
@Test
public void heapifyFromCompactSketch() {
final int k = 8;
final int n = 177;
// assuming reverse ordered inserts
final UpdateDoublesSketch qs = buildAndLoadQS(k, n);
final byte[] qsBytes = qs.compact().toByteArray();
final Memory qsMem = Memory.wrap(qsBytes);
final HeapCompactDoublesSketch compactQs = HeapCompactDoublesSketch.heapifyInstance(qsMem);
DoublesSketchTest.testSketchEquality(qs, compactQs);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkZeroPatternReturn.
@Test
public void checkZeroPatternReturn() {
int k = PreambleUtil.DEFAULT_K;
DoublesSketch qs1 = buildAndLoadQS(k, 64);
byte[] byteArr = qs1.toByteArray();
Memory mem = Memory.wrap(byteArr);
HeapUpdateDoublesSketch.heapifyInstance(mem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method checkToFromByteArray2.
private static void checkToFromByteArray2(int k, int n) {
DoublesSketch qs = buildAndLoadQS(k, n);
byte[] byteArr;
Memory mem;
DoublesSketch qs2;
// from compact
byteArr = qs.toByteArray(true);
mem = Memory.wrap(byteArr);
qs2 = UpdateDoublesSketch.heapify(mem);
for (double f = 0.1; f < 0.95; f += 0.1) {
assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0);
}
// ordered, non-compact
byteArr = qs.toByteArray(false);
mem = Memory.wrap(byteArr);
qs2 = DoublesSketch.heapify(mem);
final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(qs2);
dsa.sort();
for (double f = 0.1; f < 0.95; f += 0.1) {
assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0);
}
// not ordered, not compact
byteArr = qs.toByteArray(false);
mem = Memory.wrap(byteArr);
qs2 = DoublesSketch.heapify(mem);
for (double f = 0.1; f < 0.95; f += 0.1) {
assertEquals(qs.getQuantile(f), qs2.getQuantile(f), 0.0);
}
}
use of com.yahoo.memory.Memory 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);
}
Aggregations