use of com.yahoo.sketches.ArrayOfLongsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method serializeLongDeserialize.
@Test
public void serializeLongDeserialize() {
ItemsSketch<Long> sketch1 = new ItemsSketch<Long>(1 << LG_MIN_MAP_SIZE);
sketch1.update(1L);
sketch1.update(2L);
sketch1.update(3L);
sketch1.update(4L);
String s = sketch1.toString();
println(s);
byte[] bytes = sketch1.toByteArray(new ArrayOfLongsSerDe());
ItemsSketch<Long> sketch2 = ItemsSketch.getInstance(Memory.wrap(bytes), new ArrayOfLongsSerDe());
sketch2.update(2L);
sketch2.update(3L);
sketch2.update(2L);
Assert.assertFalse(sketch2.isEmpty());
Assert.assertEquals(sketch2.getNumActiveItems(), 4);
Assert.assertEquals(sketch2.getStreamLength(), 7);
Assert.assertEquals(sketch2.getEstimate(1L), 1);
Assert.assertEquals(sketch2.getEstimate(2L), 3);
Assert.assertEquals(sketch2.getEstimate(3L), 2);
Assert.assertEquals(sketch2.getEstimate(4L), 1);
}
use of com.yahoo.sketches.ArrayOfLongsSerDe in project sketches-core by DataSketches.
the class ItemsSketchTest method tryBadMem.
private static void tryBadMem(WritableMemory mem, int byteOffset, int byteValue) {
ArrayOfLongsSerDe serDe = new ArrayOfLongsSerDe();
try {
//Corrupt
mem.putByte(byteOffset, (byte) byteValue);
ItemsSketch.getInstance(mem, serDe);
fail();
} catch (SketchesArgumentException e) {
//expected
}
}
Aggregations