use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectIntersectionTest method checkOverlappedDirect.
//Check Alex's bug intersecting 2 direct full sketches with only overlap of 2
//
@Test
public void checkOverlappedDirect() {
int k = 1 << 4;
//plenty of room
int memBytes = 2 * k * 16 + PREBYTES;
UpdateSketch sk1 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
UpdateSketch sk2 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i = 0; i < k; i++) {
sk1.update(i);
//overlap by 2
sk2.update(k - 2 + i);
}
WritableMemory memIn1 = WritableMemory.wrap(new byte[memBytes]);
WritableMemory memIn2 = WritableMemory.wrap(new byte[memBytes]);
WritableMemory memOut = WritableMemory.wrap(new byte[memBytes]);
CompactSketch csk1 = sk1.compact(true, memIn1);
CompactSketch csk2 = sk2.compact(true, memIn2);
Intersection inter = Sketches.setOperationBuilder().buildIntersection(memOut);
inter.update(csk1);
inter.update(csk2);
CompactSketch cskOut = inter.getResult(true, memOut);
assertEquals(cskOut.getEstimate(), 2.0, 0.0);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkResetAndStartingSubMultiple.
@Test
public void checkResetAndStartingSubMultiple() {
int k = 512;
int u = 4 * k;
WritableMemory mem = makeNativeMemory(k);
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
//for internal checks
DirectQuickSelectSketch sk1 = (DirectQuickSelectSketch) usk;
assertTrue(usk.isEmpty());
for (int i = 0; i < u; i++) {
usk.update(i);
}
assertFalse(usk.isEmpty());
assertTrue(sk1.getRetainedEntries(false) > k);
assertTrue(sk1.getThetaLong() < Long.MAX_VALUE);
sk1.reset();
assertTrue(usk.isEmpty());
assertEquals(sk1.getRetainedEntries(false), 0);
assertEquals(usk.getEstimate(), 0.0, 0.0);
assertEquals(sk1.getThetaLong(), Long.MAX_VALUE);
assertNotNull(sk1.getMemory());
assertFalse(sk1.isOrdered());
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkRebuild.
@Test
public void checkRebuild() {
int k = 512;
int u = 4 * k;
WritableMemory mem = makeNativeMemory(k);
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
//for internal checks
DirectQuickSelectSketch sk1 = (DirectQuickSelectSketch) usk;
assertTrue(usk.isEmpty());
for (int i = 0; i < u; i++) {
usk.update(i);
}
assertFalse(usk.isEmpty());
assertTrue(usk.getEstimate() > 0.0);
assertTrue(sk1.getRetainedEntries(false) > k);
sk1.rebuild();
assertEquals(sk1.getRetainedEntries(false), k);
assertEquals(sk1.getRetainedEntries(true), k);
sk1.rebuild();
assertEquals(sk1.getRetainedEntries(false), k);
assertEquals(sk1.getRetainedEntries(true), k);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkUpperAndLowerBounds.
@Test
public void checkUpperAndLowerBounds() {
int k = 512;
int u = 2 * k;
WritableMemory mem = makeNativeMemory(k);
UpdateSketch usk = UpdateSketch.builder().setNominalEntries(k).build(mem);
for (int i = 0; i < u; i++) {
usk.update(i);
}
double est = usk.getEstimate();
double ub = usk.getUpperBound(1);
double lb = usk.getLowerBound(1);
assertTrue(ub > est);
assertTrue(lb < est);
}
use of com.yahoo.memory.WritableMemory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkConstructorMemTooSmall.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkConstructorMemTooSmall() {
int k = 16;
WritableMemory mem = makeNativeMemory(8);
UpdateSketch.builder().setNominalEntries(k).build(mem);
}
Aggregations