use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class UnionImplTest method checkFastWrap.
@Test
public void checkFastWrap() {
int k = 16;
long seed = DEFAULT_UPDATE_SEED;
int unionSize = Sketches.getMaxUnionBytes(k);
WritableMemory srcMem = WritableMemory.wrap(new byte[unionSize]);
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(srcMem);
//exact
for (int i = 0; i < k; i++) {
union.update(i);
}
assertEquals(union.getResult().getEstimate(), k, 0.0);
Union union2 = UnionImpl.fastWrap(srcMem, seed);
assertEquals(union2.getResult().getEstimate(), k, 0.0);
Memory srcMemR = srcMem;
Union union3 = UnionImpl.fastWrap(srcMemR, seed);
assertEquals(union3.getResult().getEstimate(), k, 0.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SerializerDeserializerTest method deserializeFromMemoryUsupportedClass.
@Test(expectedExceptions = SketchesArgumentException.class)
public void deserializeFromMemoryUsupportedClass() {
Memory mem = null;
SerializerDeserializer.deserializeFromMemory(mem, 0, "bogus");
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUnionTest method checkSerVer2Handling.
@Test
public void checkSerVer2Handling() {
//4096
int lgK = 12;
int k = 1 << lgK;
int u1 = 2 * k;
//smaller exact sketch forces early stop
int u2 = 1024;
int totU = u1 + u2;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
//2*k
for (int i = 0; i < u1; i++) usk1.update(i);
//2*k + 1024 no overlap
for (int i = u1; i < totU; i++) usk2.update(i);
WritableMemory skMem1 = WritableMemory.wrap(usk1.compact(true, null).toByteArray());
WritableMemory skMem2 = WritableMemory.wrap(usk2.compact(true, null).toByteArray());
Memory v2mem1 = convertSerV3toSerV2(skMem1);
Memory v2mem2 = convertSerV3toSerV2(skMem2);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
union.update(v2mem1);
union.update(v2mem2);
CompactSketch cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), totU, .05 * k);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyUnion.
@Test
public void heapifyUnion() {
Union u1 = SetOperation.builder().buildUnion();
u1.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(u1.toByteArray()).asReadOnlyBuffer());
Union u2 = (Union) SetOperation.heapify(mem);
u2.update(2);
Assert.assertEquals(u2.getResult().getEstimate(), 2.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyUpdateSketch.
@Test
public void heapifyUpdateSketch() {
UpdateSketch us1 = UpdateSketch.builder().build();
us1.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(us1.toByteArray()).asReadOnlyBuffer());
// downcasting is not recommended, for testing only
UpdateSketch us2 = (UpdateSketch) Sketch.heapify(mem);
us2.update(2);
assertEquals(us2.getEstimate(), 2.0);
}
Aggregations