use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifySparseSketch.
@Test
public void heapifySparseSketch() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(false));
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 wrapEmptyCompactSketch.
@Test
public void wrapEmptyCompactSketch() {
final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
final Memory mem = Memory.wrap(s1.compact().toByteArray());
// compact, so this is ok
DoublesSketch s2 = DoublesSketch.wrap(mem);
Assert.assertTrue(s2.isEmpty());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyEmptyCompactSketch.
@Test
public void heapifyEmptyCompactSketch() {
final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact();
final Memory mem = Memory.wrap(s1.toByteArray());
DoublesSketch s2 = DoublesSketch.heapify(mem);
Assert.assertTrue(s2.isEmpty());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapCompactSketch.
@Test
public void wrapCompactSketch() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
//Memory mem = Memory.wrap(ByteBuffer.wrap(s1.compact().toByteArray()).asReadOnlyBuffer());
final Memory mem = Memory.wrap(s1.compact().toByteArray());
// compact, so this is ok
final DoublesSketch s2 = DoublesSketch.wrap(mem);
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 2.0);
Assert.assertEquals(s2.getN(), 2);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyUnionFromCompact.
@Test
public void heapifyUnionFromCompact() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(true));
DoublesUnion u = DoublesUnionBuilder.heapify(mem);
u.update(3);
DoublesSketch s2 = u.getResult();
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 3.0);
}
Aggregations