use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapAndTryUpdatingUnion.
@Test
public void wrapAndTryUpdatingUnion() {
Union u1 = SetOperation.builder().buildUnion();
u1.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(u1.toByteArray()).asReadOnlyBuffer());
Union u2 = (Union) SetOperation.wrap(mem);
Assert.assertEquals(u2.getResult().getEstimate(), 1.0);
boolean thrown = false;
try {
u2.update(2);
} catch (SketchesReadOnlyException e) {
thrown = true;
}
Assert.assertTrue(thrown);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapAndTryUpdatingUpdateSketch.
@Test
public void wrapAndTryUpdatingUpdateSketch() {
UpdateSketch updateSketch = UpdateSketch.builder().build();
updateSketch.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.toByteArray()).asReadOnlyBuffer());
UpdateSketch sketch = (UpdateSketch) Sketch.wrap(mem);
assertEquals(sketch.getEstimate(), 1.0);
boolean thrown = false;
try {
sketch.update(2);
} catch (SketchesReadOnlyException e) {
thrown = true;
}
Assert.assertTrue(thrown);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapCompactUnorderedSketch.
@Test
public void wrapCompactUnorderedSketch() {
UpdateSketch updateSketch = UpdateSketch.builder().build();
updateSketch.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact(false, null).toByteArray()).asReadOnlyBuffer());
Sketch sketch = Sketch.wrap(mem);
assertEquals(sketch.getEstimate(), 1.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapIntersectionTest method checkFamilyID.
@Test(expectedExceptions = ClassCastException.class)
public void checkFamilyID() {
int k = 32;
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
byte[] byteArray = union.toByteArray();
Memory mem = Memory.wrap(byteArray);
//bad cast
Intersection inter1 = (Intersection) SetOperation.heapify(mem);
println(inter1.toString());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DirectQuickSelectSketchTest method checkHeapifyByteArrayEstimating.
@Test
public void checkHeapifyByteArrayEstimating() {
int k = 4096;
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 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);
Sketch usk2 = Sketch.heapify(srcMem);
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(), "HeapQuickSelectSketch");
}
Aggregations