use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method serializeStringDeserializeEmpty.
@Test
public void serializeStringDeserializeEmpty() {
ItemsSketch<String> sketch1 = new ItemsSketch<>(1 << LG_MIN_MAP_SIZE);
byte[] bytes = sketch1.toByteArray(new ArrayOfStringsSerDe());
ItemsSketch<String> sketch2 = ItemsSketch.getInstance(Memory.wrap(bytes), new ArrayOfStringsSerDe());
Assert.assertTrue(sketch2.isEmpty());
Assert.assertEquals(sketch2.getNumActiveItems(), 0);
Assert.assertEquals(sketch2.getStreamLength(), 0);
}
use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class ReservoirItemsSketchTest method checkEmptySketch.
@Test
public void checkEmptySketch() {
final ReservoirItemsSketch<String> ris = ReservoirItemsSketch.newInstance(5);
assertTrue(ris.getSamples() == null);
final byte[] sketchBytes = ris.toByteArray(new ArrayOfStringsSerDe());
final Memory mem = Memory.wrap(sketchBytes);
// only minPreLongs bytes and should deserialize to empty
assertEquals(sketchBytes.length, Family.RESERVOIR.getMinPreLongs() << 3);
final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
final ReservoirItemsSketch<String> loadedRis = ReservoirItemsSketch.heapify(mem, serDe);
assertEquals(loadedRis.getNumSamples(), 0);
println("Empty sketch:");
println(" Preamble:");
println(PreambleUtil.preambleToString(mem));
println(" Sketch:");
println(ris.toString());
}
use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class VarOptItemsSketchTest method checkEmptySketch.
@Test
public void checkEmptySketch() {
final VarOptItemsSketch<String> vis = VarOptItemsSketch.newInstance(5);
assertEquals(vis.getN(), 0);
assertEquals(vis.getNumSamples(), 0);
assertNull(vis.getSamplesAsArrays());
assertNull(vis.getSamplesAsArrays(Long.class));
final byte[] sketchBytes = vis.toByteArray(new ArrayOfStringsSerDe());
final Memory mem = Memory.wrap(sketchBytes);
// only minPreLongs bytes and should deserialize to empty
assertEquals(sketchBytes.length, Family.VAROPT.getMinPreLongs() << 3);
final ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
final VarOptItemsSketch<String> loadedVis = VarOptItemsSketch.heapify(mem, serDe);
assertEquals(loadedVis.getNumSamples(), 0);
println("Empty sketch:");
println(" Preamble:");
VarOptItemsSketch.toString(sketchBytes);
println(VarOptItemsSketch.toString(mem));
println(" Sketch:");
println(vis.toString());
}
use of org.apache.datasketches.ArrayOfStringsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method checkGetInstanceExcep2.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkGetInstanceExcep2() {
final Memory mem = Memory.wrap(new byte[8]);
ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
use of org.apache.datasketches.ArrayOfStringsSerDe 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());
}
Aggregations