use of com.yahoo.memory.WritableMemory 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);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method check2ndCallAfterNull.
@Test
public void check2ndCallAfterNull() {
int lgK = 9;
int k = 1 << lgK;
Intersection inter;
UpdateSketch sk;
CompactSketch comp1;
double est;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//1st call = null
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(null);
//2nd call = null
inter.update(null);
comp1 = inter.getResult(false, null);
est = comp1.getEstimate();
assertEquals(est, 0.0, 0.0);
println("Est: " + est);
//1st call = null
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(null);
//2nd call = empty
//empty
sk = UpdateSketch.builder().build();
inter.update(sk);
comp1 = inter.getResult(false, null);
est = comp1.getEstimate();
assertEquals(est, 0.0, 0.0);
println("Est: " + est);
//1st call = null
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(null);
//2nd call = valid & not empty
sk = UpdateSketch.builder().build();
sk.update(1);
inter.update(sk);
comp1 = inter.getResult(false, null);
est = comp1.getEstimate();
assertEquals(est, 0.0, 0.0);
println("Est: " + est);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkEstimatingIntersect.
@Test
public void checkEstimatingIntersect() {
int lgK = 9;
int k = 1 << lgK;
Intersection inter;
UpdateSketch sk1, sk2;
CompactSketch comp1;
double est;
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);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkOverflow.
@SuppressWarnings("unused")
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkOverflow() {
//512
int lgK = 9;
int k = 1 << lgK;
Intersection inter;
UpdateSketch sk1, sk2;
CompactSketch comp1;
double est;
int reqBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[reqBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//1st call = valid
// bigger sketch
sk1 = UpdateSketch.builder().setNominalEntries(2 * k).build();
//force est mode
for (int i = 0; i < 4 * k; i++) sk1.update(i);
println("sk1est: " + sk1.getEstimate());
println("sk1cnt: " + sk1.getRetainedEntries(true));
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(sk1);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkBadSerVer.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSerVer() {
int k = 32;
Intersection inter1;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//virgin
inter1 = SetOperation.builder().buildIntersection(iMem);
byte[] byteArray = inter1.toByteArray();
WritableMemory mem = WritableMemory.wrap(byteArray);
//corrupt:
mem.putByte(SER_VER_BYTE, (byte) 2);
//throws in SetOperations
Sketches.wrapIntersection(mem);
}
Aggregations