use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkDQStoCompactEmptyForms.
@Test
public void checkDQStoCompactEmptyForms() {
int k = 512;
WritableMemory mem = makeNativeMemory(k);
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
//empty
//exercise toString
usk.toString(false, true, 0, false);
assertEquals(usk.getClass().getSimpleName(), "DirectQuickSelectSketch");
double uskEst = usk.getEstimate();
double uskLB = usk.getLowerBound(2);
double uskUB = usk.getUpperBound(2);
assertEquals(usk.isEstimationMode(), false);
//compact form
int bytes = usk.getCurrentBytes(true);
assertEquals(bytes, 8);
byte[] memArr2 = new byte[bytes];
WritableMemory mem2 = WritableMemory.wrap(memArr2);
CompactSketch csk2 = usk.compact(false, mem2);
assertEquals(csk2.getEstimate(), uskEst);
assertEquals(csk2.getLowerBound(2), uskLB);
assertEquals(csk2.getUpperBound(2), uskUB);
assertEquals(csk2.isEmpty(), true);
assertEquals(csk2.isEstimationMode(), false);
assertEquals(csk2.getClass().getSimpleName(), "DirectCompactSketch");
CompactSketch csk3 = usk.compact(true, mem2);
csk3.toString(false, true, 0, false);
csk3.toString();
assertEquals(csk3.getEstimate(), uskEst);
assertEquals(csk3.getLowerBound(2), uskLB);
assertEquals(csk3.getUpperBound(2), uskUB);
assertEquals(csk3.isEmpty(), true);
assertEquals(csk3.isEstimationMode(), false);
assertEquals(csk3.getClass().getSimpleName(), "DirectCompactOrderedSketch");
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkSamplingMode.
@Test
public void checkSamplingMode() {
int k = 4096;
float p = (float) 0.5;
WritableMemory mem = makeNativeMemory(k);
UpdateSketch usk = UpdateSketch.builder().setP(p).setNominalEntries(k).build(mem);
//for internal checks
DirectQuickSelectSketch sk1 = (DirectQuickSelectSketch) usk;
for (int i = 0; i < k; i++) {
usk.update(i);
}
double p2 = sk1.getP();
double theta = sk1.getTheta();
assertTrue(theta <= p2);
double est = usk.getEstimate();
assertEquals(k, est, k * .05);
double ub = usk.getUpperBound(1);
assertTrue(ub > est);
double lb = usk.getLowerBound(1);
assertTrue(lb < est);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkFamilyAndRF.
@Test
public void checkFamilyAndRF() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + 24]);
UpdateSketch sketch = Sketches.updateSketchBuilder().setNominalEntries(k).build(mem);
assertEquals(sketch.getFamily(), Family.QUICKSELECT);
assertEquals(sketch.getResizeFactor(), ResizeFactor.X8);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkGetFamily.
@Test
public void checkGetFamily() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[k * 16 + 32]);
SetOperation setOp = new SetOperationBuilder().setNominalEntries(k).build(Family.UNION, mem);
assertEquals(setOp.getFamily(), Family.UNION);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectUnionTest method checkExactUnionNoOverlap.
@Test
public void checkExactUnionNoOverlap() {
//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);
}
Aggregations