use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method quantilesCheckViaMemory.
//@Test //visual only
public void quantilesCheckViaMemory() {
int k = 256;
int n = 1000000;
DoublesSketch qs = buildAndLoadQS(k, n);
double[] ranks = { 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 };
String s = getRanksTable(qs, ranks);
println(s);
println("");
Memory srcMem = Memory.wrap(qs.toByteArray());
HeapUpdateDoublesSketch qs2 = HeapUpdateDoublesSketch.heapifyInstance(srcMem);
println(getRanksTable(qs2, ranks));
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUpdateDoublesSketchTest method serializeDeserializeEmptyNonCompact.
@Test
public void serializeDeserializeEmptyNonCompact() {
UpdateDoublesSketch sketch1 = DoublesSketch.builder().build();
//Ordered, Not Compact, Empty
byte[] byteArr = sketch1.toByteArray(false);
assertEquals(byteArr.length, sketch1.getStorageBytes());
Memory mem = Memory.wrap(byteArr);
UpdateDoublesSketch sketch2 = (UpdateDoublesSketch) DoublesSketch.heapify(mem);
for (int i = 0; i < 1000; i++) {
sketch2.update(i);
}
assertEquals(sketch2.getMinValue(), 0.0);
assertEquals(sketch2.getMaxValue(), 999.0);
assertEquals(sketch2.getQuantile(0.5), 500.0, 4.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ItemsSketchTest method checkGoodSerDeId.
@Test
public void checkGoodSerDeId() {
ItemsSketch<String> sketch = ItemsSketch.getInstance(Comparator.naturalOrder());
byte[] byteArr = sketch.toByteArray(new ArrayOfStringsSerDe());
Memory mem = Memory.wrap(byteArr);
//println(PreambleUtil.toString(mem));
ItemsSketch.getInstance(mem, Comparator.naturalOrder(), new ArrayOfStringsSerDe());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ItemsSketchTest method checkToFromByteArray2.
private static void checkToFromByteArray2(int k, int n) {
ItemsSketch<String> is = buildStringIS(k, n);
byte[] byteArr;
Memory mem;
ItemsSketch<String> is2;
ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe();
//ordered
byteArr = is.toByteArray(true, serDe);
mem = Memory.wrap(byteArr);
is2 = ItemsSketch.getInstance(mem, Comparator.naturalOrder(), serDe);
for (double f = 0.1; f < 0.95; f += 0.1) {
assertEquals(is.getQuantile(f), is2.getQuantile(f));
}
//Not-ordered
byteArr = is.toByteArray(false, serDe);
mem = Memory.wrap(byteArr);
is2 = ItemsSketch.getInstance(mem, Comparator.naturalOrder(), serDe);
for (double f = 0.1; f < 0.95; f += 0.1) {
assertEquals(is.getQuantile(f), is2.getQuantile(f));
}
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkHeapify.
@Test
public void checkHeapify() {
int lgK = 9;
int k = 1 << lgK;
Intersection inter;
UpdateSketch sk1, sk2;
CompactSketch comp1, comp2;
double est, est2;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//1st call = valid
sk1 = UpdateSketch.builder().setNominalEntries(k).build();
//est mode
for (int i = 0; i < 2 * k; i++) sk1.update(i);
println("sk1: " + sk1.getEstimate());
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(sk1);
//2nd call = valid intersecting
sk2 = UpdateSketch.builder().setNominalEntries(k).build();
//est mode
for (int i = 0; i < 2 * k; i++) sk2.update(i);
println("sk2: " + sk2.getEstimate());
inter.update(sk2);
comp1 = inter.getResult(false, null);
est = comp1.getEstimate();
assertTrue(est > k);
println("Est: " + est);
byte[] byteArray = inter.toByteArray();
Memory mem = Memory.wrap(byteArray);
Intersection inter2 = (Intersection) SetOperation.heapify(mem);
comp2 = inter2.getResult(false, null);
est2 = comp2.getEstimate();
println("Est2: " + est2);
}
Aggregations