use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method summaryCheckViaMemory.
//@Test //visual only
public void summaryCheckViaMemory() {
DoublesSketch qs = buildAndLoadQS(256, 1000000);
String s = qs.toString();
println(s);
println("");
Memory srcMem = WritableMemory.wrap(qs.toByteArray());
HeapUpdateDoublesSketch qs2 = HeapUpdateDoublesSketch.heapifyInstance(srcMem);
s = qs2.toString();
println(s);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class VarOptItemsUnionTest method serializeSamplingUnion.
@Test
public void serializeSamplingUnion() {
final int n = 256;
final int k = 128;
final VarOptItemsSketch<Long> sketch = getUnweightedLongsVIS(k, n);
sketch.update(n + 1L, 1000.0);
sketch.update(n + 2L, 1001.0);
sketch.update(n + 3L, 1002.0);
sketch.update(n + 4L, 1003.0);
sketch.update(n + 5L, 1004.0);
sketch.update(n + 6L, 1005.0);
sketch.update(n + 7L, 1006.0);
sketch.update(n + 8L, 1007.0);
final VarOptItemsUnion<Long> union = VarOptItemsUnion.newInstance(k);
union.update(sketch);
final ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe();
final byte[] unionBytes = union.toByteArray(serDe);
final Memory mem = Memory.wrap(unionBytes);
final VarOptItemsUnion<Long> rebuilt = VarOptItemsUnion.heapify(mem, serDe);
compareUnions(rebuilt, union);
assertEquals(rebuilt.toString(), union.toString());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyCompactSketch.
@Test
public void heapifyCompactSketch() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(true));
DoublesSketch s2 = DoublesSketch.heapify(mem);
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 2.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapAndTryUpdatingSparseSketch.
@Test
public void wrapAndTryUpdatingSparseSketch() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
final byte[] bytes = s1.toByteArray(false);
// 32 + MIN_K(=2) * 2 * 8 = 64
Assert.assertEquals(bytes.length, 64);
//final Memory mem = Memory.wrap(ByteBuffer.wrap(bytes).asReadOnlyBuffer());
final Memory mem = Memory.wrap(bytes);
final UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.wrap(mem);
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 2.0);
try {
s2.update(3);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapUnionFromCompact.
@Test(expectedExceptions = SketchesArgumentException.class)
public void wrapUnionFromCompact() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(true));
DoublesUnionBuilder.wrap(mem);
fail();
}
Aggregations