use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class ItemsSketchTest method checkGoodSerDeId.
@Test
public void checkGoodSerDeId() {
final ItemsSketch<String> sketch = ItemsSketch.getInstance(Comparator.naturalOrder());
final byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe());
final Memory mem = Memory.wrap(byteArr);
// println(PreambleUtil.toString(mem));
ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapUnionFromSparse.
@Test
public void wrapUnionFromSparse() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(false));
DoublesUnion u = DoublesUnion.wrap(mem);
DoublesSketch s2 = u.getResult();
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 2.0);
// ensure update and reset methods fail
try {
u.update(3);
fail();
} catch (SketchesReadOnlyException e) {
// expected
}
try {
u.update(s2);
fail();
} catch (SketchesReadOnlyException e) {
// expected
}
try {
u.update(mem);
fail();
} catch (SketchesReadOnlyException e) {
// expected
}
try {
u.reset();
fail();
} catch (SketchesReadOnlyException e) {
// expected
}
try {
u.getResultAndReset();
fail();
} catch (SketchesReadOnlyException e) {
// expected
}
}
use of org.apache.datasketches.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 org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyAndUpdateSparseSketch.
@Test
public void heapifyAndUpdateSparseSketch() {
UpdateDoublesSketch s1 = DoublesSketch.builder().build();
s1.update(1);
s1.update(2);
Memory mem = Memory.wrap(s1.toByteArray(false));
UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.heapify(mem);
s2.update(3);
Assert.assertEquals(s2.getMinValue(), 1.0);
Assert.assertEquals(s2.getMaxValue(), 3.0);
}
use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapEmptyUpdateSketch.
@Test
public void wrapEmptyUpdateSketch() {
final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
final Memory mem = Memory.wrap(s1.toByteArray());
UpdateDoublesSketch s2 = (UpdateDoublesSketch) DoublesSketch.wrap(mem);
Assert.assertTrue(s2.isEmpty());
// ensure the various put calls fail
try {
s2.putMinValue(-1.0);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.putMaxValue(1.0);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.putN(1);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.putBitPattern(1);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.reset();
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.putBaseBufferCount(5);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
s2.putCombinedBuffer(new double[16]);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
try {
final int currCap = s2.getCombinedBufferItemCapacity();
s2.growCombinedBuffer(currCap, 2 * currCap);
fail();
} catch (final SketchesReadOnlyException e) {
// expected
}
}
Aggregations