use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkSerVer2Handling.
@Test
public void checkSerVer2Handling() {
//4096
int lgK = 12;
int k = 1 << lgK;
int u1 = 2 * k;
//smaller exact sketch forces early stop
int u2 = 1024;
int totU = u1 + u2;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
//2*k
for (int i = 0; i < u1; i++) usk1.update(i);
//2*k + 1024 no overlap
for (int i = u1; i < totU; i++) usk2.update(i);
WritableMemory skMem1 = WritableMemory.wrap(usk1.compact(true, null).toByteArray());
WritableMemory skMem2 = WritableMemory.wrap(usk2.compact(true, null).toByteArray());
Memory v2mem1 = convertSerV3toSerV2(skMem1);
Memory v2mem2 = convertSerV3toSerV2(skMem2);
//union memory
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v2mem1);
union.update(v2mem2);
CompactSketch cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), totU, .05 * k);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkSizeTooSmall.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkSizeTooSmall() {
int k = 16;
//initialized
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + 32]);
SetOperation setOp = new SetOperationBuilder().setNominalEntries(k).build(Family.UNION, mem);
println(setOp.toString());
//for just preamble
WritableMemory mem2 = WritableMemory.wrap(new byte[32]);
//too small
mem.copyTo(0, mem2, 0, 32);
DirectQuickSelectSketch.writableWrap(mem2, Util.DEFAULT_UPDATE_SEED);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkDirectWrap.
//Special DirectUnion cases
//Himanshu's issue
@Test
public void checkDirectWrap() {
int nomEntries = 16;
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(nomEntries)]);
SetOperation.builder().setNominalEntries(nomEntries).buildUnion(uMem);
UpdateSketch sk1 = UpdateSketch.builder().setNominalEntries(nomEntries).build();
sk1.update("a");
sk1.update("b");
UpdateSketch sk2 = UpdateSketch.builder().setNominalEntries(nomEntries).build();
sk2.update("c");
sk2.update("d");
Union union = Sketches.wrapUnion(uMem);
union.update(sk1);
union = Sketches.wrapUnion(uMem);
union.update(sk2);
CompactSketch sketch = union.getResult(true, null);
assertEquals(4.0, sketch.getEstimate(), 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkWrapExact.
//these parallel the checkHeapifyExact, etc.
@Test
public void checkWrapExact() {
//512
int lgK = 9;
int k = 1 << lgK;
int u = k;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
//256
for (int i = 0; i < u / 2; i++) usk1.update(i);
//256 no overlap
for (int i = u / 2; i < u; i++) usk2.update(i);
//exact, no overlap
assertEquals(u, usk1.getEstimate() + usk2.getEstimate(), 0.0);
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
//update with heap UpdateSketch
union.update(usk1);
//update with heap UpdateSketch
union.update(usk2);
testAllCompactForms(union, u, 0.0);
Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));
testAllCompactForms(union2, u, 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkEmptyUnionCompactOrderedResult.
@Test
public void checkEmptyUnionCompactOrderedResult() {
int k = 64;
//union memory
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
WritableMemory mem = WritableMemory.wrap(new byte[Sketch.getMaxCompactSketchBytes(0)]);
//DirectCompactSketch
CompactSketch csk = union.getResult(true, mem);
assertTrue(csk.isEmpty());
}
Aggregations