use of org.apache.datasketches.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().order(ByteOrder.nativeOrder())););
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 org.apache.datasketches.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 org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class DirectCompactDoublesSketchTest method wrapEmptyCompactSketch.
@Test
public void wrapEmptyCompactSketch() {
final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact();
final Memory mem = Memory.wrap(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder()));
final DoublesSketch s2 = DoublesSketch.wrap(mem);
assertTrue(s2.isEmpty());
assertEquals(s2.getN(), 0);
assertTrue(Double.isNaN(s2.getMinValue()));
assertTrue(Double.isNaN(s2.getMaxValue()));
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class DirectCompactDoublesSketchTest method wrapFromUpdateSketch.
@Test(expectedExceptions = SketchesArgumentException.class)
public void wrapFromUpdateSketch() {
final int k = 4;
final int n = 27;
final UpdateDoublesSketch qs = HeapUpdateDoublesSketchTest.buildAndLoadQS(k, n);
final byte[] qsBytes = qs.toByteArray();
final Memory qsMem = Memory.wrap(qsBytes);
DirectCompactDoublesSketch.wrapInstance(qsMem);
fail();
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class DirectCompactDoublesSketchTest method wrapFromCompactSketch.
@Test
public void wrapFromCompactSketch() {
final int k = 8;
final int n = 177;
// assuming ordered inserts
final DirectCompactDoublesSketch qs = buildAndLoadDCQS(k, n);
final byte[] qsBytes = qs.toByteArray();
final Memory qsMem = Memory.wrap(qsBytes);
final DirectCompactDoublesSketch compactQs = DirectCompactDoublesSketch.wrapInstance(qsMem);
DoublesSketchTest.testSketchEquality(qs, compactQs);
assertEquals(qsBytes.length, compactQs.getStorageBytes());
final double[] combinedBuffer = compactQs.getCombinedBuffer();
assertEquals(combinedBuffer.length, compactQs.getCombinedBufferItemCapacity());
}
Aggregations