use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkPreambleLongsCorruption.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkPreambleLongsCorruption() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + 32]);
//may be null
Object memObj = mem.getArray();
long memAdd = mem.getCumulativeOffset(0L);
SetOperation setOp = new SetOperationBuilder().setNominalEntries(k).build(Family.UNION, mem);
println(setOp.toString());
int familyID = PreambleUtil.extractFamilyID(memObj, memAdd);
int preLongs = PreambleUtil.extractPreLongs(memObj, memAdd);
assertEquals(familyID, Family.UNION.getID());
assertEquals(preLongs, Family.UNION.getMaxPreLongs());
//Corrupt with 3; correct value is 4
PreambleUtil.insertPreLongs(memObj, memAdd, 3);
DirectQuickSelectSketch.writableWrap(mem, Util.DEFAULT_UPDATE_SEED);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkUnionMemToString.
@Test
public void checkUnionMemToString() {
int k = 64;
//union memory
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkWrapEstNoOverlapOrderedIn.
@Test
public void checkWrapEstNoOverlapOrderedIn() {
//4096
int lgK = 12;
int k = 1 << lgK;
int u = 4 * k;
//2k estimating
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
//2k exact for early stop test
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(2 * k).build();
//2k estimating
for (int i = 0; i < u / 2; i++) usk1.update(i);
//2k no overlap, exact, will force early stop
for (int i = u / 2; i < u; i++) usk2.update(i);
CompactSketch cosk2 = usk2.compact(true, null);
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 Compact, Ordered input, early stop
union.update(cosk2);
UpdateSketch emptySketch = UpdateSketch.builder().setNominalEntries(k).build();
//updates with empty
union.update(emptySketch);
emptySketch = null;
//updates with null
union.update(emptySketch);
testAllCompactForms(union, u, 0.05);
Union union2 = Sketches.wrapUnion(WritableMemory.wrap(union.toByteArray()));
testAllCompactForms(union2, u, 0.05);
union2.reset();
assertEquals(union2.getResult(true, null).getEstimate(), 0.0, 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkEstUnionNoOverlap.
@Test
public void checkEstUnionNoOverlap() {
//4096
int lgK = 12;
int k = 1 << lgK;
int u = 4 * k;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
//2*k
for (int i = 0; i < u / 2; i++) usk1.update(i);
//2*k no overlap
for (int i = u / 2; i < u; i++) usk2.update(i);
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.05);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class HeapAnotBTest method checkExactAnotB_AvalidNoOverlap.
@Test
public void checkExactAnotB_AvalidNoOverlap() {
int k = 512;
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);
AnotB aNb = SetOperation.builder().buildANotB();
aNb.update(usk1, usk2);
CompactSketch rsk1;
rsk1 = aNb.getResult(false, null);
assertEquals(rsk1.getEstimate(), k / 2.0);
aNb.update(usk1, usk2);
rsk1 = aNb.getResult(true, null);
assertEquals(rsk1.getEstimate(), k / 2.0);
//getCurrentBytes( compact )
int bytes = rsk1.getCurrentBytes(true);
byte[] byteArray = new byte[bytes];
WritableMemory mem = WritableMemory.wrap(byteArray);
aNb.update(usk1, usk2);
rsk1 = aNb.getResult(false, mem);
assertEquals(rsk1.getEstimate(), k / 2.0);
aNb.update(usk1, usk2);
rsk1 = aNb.getResult(true, mem);
assertEquals(rsk1.getEstimate(), k / 2.0);
}
Aggregations