use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchesTest method checkStaticEstimators.
@Test
public void checkStaticEstimators() {
int k = 4096;
int u = 4 * k;
Memory srcMem = getCompactSketch(k, 0, u);
double est = Sketches.getEstimate(srcMem);
assertEquals(est, u, 0.05 * u);
double rse = 1.0 / Math.sqrt(k);
double ub = Sketches.getUpperBound(1, srcMem);
assertEquals(ub, est + rse, 0.05 * u);
double lb = Sketches.getLowerBound(1, srcMem);
assertEquals(lb, est - rse, 0.05 * u);
Memory memV1 = convertSerV3toSerV1(srcMem);
boolean empty = Sketches.getEmpty(memV1);
assertFalse(empty);
Memory emptyMemV3 = getCompactSketch(k, 0, 0);
assertEquals(Sketches.getRetainedEntries(emptyMemV3), 0);
assertEquals(Sketches.getThetaLong(emptyMemV3), Long.MAX_VALUE);
Memory emptyMemV1 = convertSerV3toSerV1(emptyMemV3);
empty = Sketches.getEmpty(emptyMemV1);
assertTrue(empty);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchesTest method checkBadSketchFamily.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadSketchFamily() {
Union union = setOperationBuilder().buildUnion();
byte[] byteArr = union.toByteArray();
Memory srcMem = Memory.wrap(byteArr);
Sketches.getEstimate(srcMem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchesTest method checkSketchMethods.
@Test
public void checkSketchMethods() {
int k = 1024;
Memory mem = getCompactSketch(k, 0, k);
CompactSketch csk2 = (CompactSketch) heapifySketch(mem);
assertEquals((int) csk2.getEstimate(), k);
csk2 = (CompactSketch) heapifySketch(mem, Util.DEFAULT_UPDATE_SEED);
assertEquals((int) csk2.getEstimate(), k);
csk2 = (CompactSketch) wrapSketch(mem);
//TODO fails
assertEquals((int) csk2.getEstimate(), k);
csk2 = (CompactSketch) wrapSketch(mem, Util.DEFAULT_UPDATE_SEED);
assertEquals((int) csk2.getEstimate(), k);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest method checkHeapifyByteArrayEstimating.
@Test
public void checkHeapifyByteArrayEstimating() {
int k = 4096;
int u = 2 * k;
long seed = DEFAULT_UPDATE_SEED;
UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setSeed(seed).setNominalEntries(k).build();
for (int i = 0; i < u; i++) usk.update(i);
double uskEst = usk.getEstimate();
double uskLB = usk.getLowerBound(2);
double uskUB = usk.getUpperBound(2);
assertEquals(usk.isEstimationMode(), true);
byte[] byteArray = usk.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
UpdateSketch usk2 = UpdateSketch.heapify(srcMem, seed);
assertEquals(usk2.getEstimate(), uskEst);
assertEquals(usk2.getLowerBound(2), uskLB);
assertEquals(usk2.getUpperBound(2), uskUB);
assertEquals(usk2.isEmpty(), false);
assertEquals(usk2.isEstimationMode(), true);
assertEquals(usk2.getClass().getSimpleName(), usk.getClass().getSimpleName());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest method checkHeapifyMemoryEstimating.
@Test
public void checkHeapifyMemoryEstimating() {
int k = 512;
int u = 2 * k;
long seed = DEFAULT_UPDATE_SEED;
boolean estimating = (u > k);
UpdateSketch sk1 = UpdateSketch.builder().setFamily(fam_).setSeed(seed).setNominalEntries(k).build();
for (int i = 0; i < u; i++) sk1.update(i);
double sk1est = sk1.getEstimate();
double sk1lb = sk1.getLowerBound(2);
double sk1ub = sk1.getUpperBound(2);
assertEquals(sk1.isEstimationMode(), estimating);
byte[] byteArray = sk1.toByteArray();
Memory mem = Memory.wrap(byteArray);
UpdateSketch sk2 = UpdateSketch.heapify(mem, DEFAULT_UPDATE_SEED);
assertEquals(sk2.getEstimate(), sk1est);
assertEquals(sk2.getLowerBound(2), sk1lb);
assertEquals(sk2.getUpperBound(2), sk1ub);
assertEquals(sk2.isEmpty(), false);
assertEquals(sk2.isEstimationMode(), estimating);
assertEquals(sk2.getClass().getSimpleName(), sk1.getClass().getSimpleName());
}
Aggregations