use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapAlphaSketchTest method checkHeapifySeedConflict.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifySeedConflict() {
int k = 512;
long seed1 = 1021;
long seed2 = DEFAULT_UPDATE_SEED;
UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setSeed(seed1).setNominalEntries(k).build();
byte[] byteArray = usk.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
Sketch.heapify(srcMem, seed2);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapAlphaSketchTest method checkHeapifyMemoryEstimating.
@Test
public void checkHeapifyMemoryEstimating() {
int k = 512;
int u = 2 * k;
long seed = DEFAULT_UPDATE_SEED;
boolean estimating = (u > k);
//int maxBytes = (k << 4) + (Family.ALPHA.getLowPreLongs());
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) Sketch.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());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyCompactUnorderedSketch.
@Test
public void heapifyCompactUnorderedSketch() {
UpdateSketch updateSketch = UpdateSketch.builder().build();
updateSketch.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact(false, null).toByteArray()).asReadOnlyBuffer());
Sketch sketch = Sketch.heapify(mem);
assertEquals(sketch.getEstimate(), 1.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchTest method checkWrapToHeapifyConversion1.
@Test
public void checkWrapToHeapifyConversion1() {
int k = 512;
UpdateSketch sketch1 = UpdateSketch.builder().setNominalEntries(k).build();
for (int i = 0; i < k; i++) {
sketch1.update(i);
}
double uest1 = sketch1.getEstimate();
int bytes = sketch1.getCurrentBytes(true);
WritableMemory v3mem = WritableMemory.wrap(new byte[bytes]);
sketch1.compact(true, v3mem);
Memory v1mem = ForwardCompatibilityTest.convertSerV3toSerV1(v3mem);
Sketch csk2 = Sketch.wrap(v1mem);
assertFalse(csk2.isDirect());
assertEquals(uest1, csk2.getEstimate(), 0.0);
Memory v2mem = ForwardCompatibilityTest.convertSerV3toSerV2(v3mem);
csk2 = Sketch.wrap(v2mem);
assertFalse(csk2.isDirect());
assertEquals(uest1, csk2.getEstimate(), 0.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchTest method checkWrapBadFamily.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkWrapBadFamily() {
UpdateSketch sketch = UpdateSketch.builder().setFamily(Family.ALPHA).setNominalEntries(1024).build();
byte[] byteArr = sketch.toByteArray();
Memory srcMem = Memory.wrap(byteArr);
Sketch.wrap(srcMem);
}
Aggregations