use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkExactIntersectionNoOverlap.
@Test
public void checkExactIntersectionNoOverlap() {
int lgK = 9;
int k = 1 << lgK;
Intersection inter;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
for (int i = 0; i < k / 2; i++) usk1.update(i);
for (int i = k / 2; i < k; i++) usk2.update(i);
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
inter = SetOperation.builder().buildIntersection(iMem);
inter.update(usk1);
inter.update(usk2);
CompactSketch rsk1;
boolean ordered = true;
assertTrue(inter.hasResult());
rsk1 = inter.getResult(!ordered, null);
assertEquals(rsk1.getEstimate(), 0.0);
rsk1 = inter.getResult(ordered, null);
assertEquals(rsk1.getEstimate(), 0.0);
boolean compact = true;
int bytes = rsk1.getCurrentBytes(compact);
byte[] byteArray = new byte[bytes];
WritableMemory mem = WritableMemory.wrap(byteArray);
rsk1 = inter.getResult(!ordered, mem);
assertEquals(rsk1.getEstimate(), 0.0);
//executed twice to fully exercise the internal state machine
rsk1 = inter.getResult(ordered, mem);
assertEquals(rsk1.getEstimate(), 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkWrapNullEmpty.
@Test
public void checkWrapNullEmpty() {
int lgK = 5;
int k = 1 << lgK;
Intersection inter1, inter2;
int memBytes = getMaxIntersectionBytes(k);
byte[] memArr = new byte[memBytes];
WritableMemory iMem = WritableMemory.wrap(memArr);
//virgin
inter1 = SetOperation.builder().buildIntersection(iMem);
inter2 = Sketches.wrapIntersection(iMem);
//both in virgin state, empty = false
assertFalse(inter1.hasResult());
assertFalse(inter2.hasResult());
//A virgin intersection intersected with null => empty = true;
inter1.update(null);
inter2 = Sketches.wrapIntersection(iMem);
assertTrue(inter1.hasResult());
assertTrue(inter2.hasResult());
CompactSketch comp = inter2.getResult(true, null);
assertEquals(comp.getRetainedEntries(false), 0);
assertTrue(comp.isEmpty());
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkFamilyID.
@Test(expectedExceptions = ClassCastException.class)
public void checkFamilyID() {
int k = 32;
Union union;
union = SetOperation.builder().setNominalEntries(k).buildUnion();
byte[] byteArray = union.toByteArray();
WritableMemory mem = WritableMemory.wrap(byteArray);
Sketches.wrapIntersection(mem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkFamily.
@Test
public void checkFamily() {
//cheap trick
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + PREBYTES]);
IntersectionImplR impl = IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
assertEquals(impl.getFamily(), Family.INTERSECTION);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkExceptions2.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkExceptions2() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + PREBYTES]);
IntersectionImpl.initNewDirectInstance(DEFAULT_UPDATE_SEED, mem);
//mem now has non-empty intersection
//corrupt empty and CurCount
mem.setBits(PreambleUtil.FLAGS_BYTE, (byte) PreambleUtil.EMPTY_FLAG_MASK);
mem.putInt(PreambleUtil.RETAINED_ENTRIES_INT, 2);
IntersectionImplR.wrapInstance(mem, DEFAULT_UPDATE_SEED);
}
Aggregations