use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method check2ndCallAfterEmpty.
@Test
public void check2ndCallAfterEmpty() {
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 = empty
//empty
sk1 = UpdateSketch.builder().build();
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(sk1);
//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 = empty
//empty
sk1 = UpdateSketch.builder().build();
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(sk1);
//2nd call = empty
//empty
sk2 = UpdateSketch.builder().build();
inter.update(sk2);
comp1 = inter.getResult(false, null);
est = comp1.getEstimate();
assertEquals(est, 0.0, 0.0);
println("Est: " + est);
//1st call = empty
//empty
sk1 = UpdateSketch.builder().build();
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(sk1);
//2nd call = valid and not empty
sk2 = UpdateSketch.builder().build();
sk2.update(1);
inter.update(sk2);
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 checkExceptionMinSize.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkExceptionMinSize() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 8 + PREBYTES]);
IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkBadPreambleLongs.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadPreambleLongs() {
int k = 32;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//virgin
Intersection inter1 = SetOperation.builder().buildIntersection(iMem);
byte[] byteArray = inter1.toByteArray();
WritableMemory mem = WritableMemory.wrap(byteArray);
//corrupt:
//RF not used = 0
mem.putByte(PREAMBLE_LONGS_BYTE, (byte) 2);
Sketches.wrapIntersection(mem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkUnion5.
@Test
public void checkUnion5() {
//Union is direct, valid and with larger K than valid input
int k2 = 4;
//8
int n2 = 2 * k2;
//big enough
int bytes = DoublesSketch.getUpdatableStorageBytes(256, 50);
WritableMemory skMem = WritableMemory.wrap(new byte[bytes]);
DoublesSketch.builder().setK(256).build(skMem);
DoublesUnion union = DoublesUnionImpl.heapifyInstance(skMem);
assertEquals(union.getResult().getN(), 0);
assertEquals(union.getMaxK(), 256);
assertEquals(union.getEffectiveK(), 256);
DoublesSketch result = union.getResult();
assertEquals(result.getK(), 256);
DoublesSketch sketchIn2 = buildAndLoadQS(k2, n2, 17);
union.update(sketchIn2);
println("\nFinal" + union.getResult().toString(true, true));
assertEquals(union.getResult().getN(), n2);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DoublesUnionImplTest method checkUnion3.
@Test
public void checkUnion3() {
//Union is direct, empty and with larger K than valid input
int k1 = 128;
int n1 = 2 * k1;
int k2 = 256;
int n2 = 2000;
DoublesSketch sketchIn1 = buildAndLoadQS(k1, n1);
//just for size
int bytes = DoublesSketch.getUpdatableStorageBytes(k2, n2);
WritableMemory mem = WritableMemory.wrap(new byte[bytes]);
//virgin 256
DoublesUnion union = DoublesUnion.builder().setMaxK(k2).build(mem);
union.update(sketchIn1);
assertEquals(union.getMaxK(), k2);
assertEquals(union.getEffectiveK(), k1);
DoublesSketch result = union.getResult();
assertEquals(result.getMaxValue(), n1, 0.0);
assertEquals(result.getMinValue(), 1.0, 0.0);
assertEquals(result.getK(), k1);
}
Aggregations