use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SetOperationTest method checkIllegalSetOpWrap.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkIllegalSetOpWrap() {
int k = 64;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
for (int i = 0; i < k; i++) {
//64
usk1.update(i);
}
byte[] byteArray = usk1.toByteArray();
Memory mem = Memory.wrap(byteArray);
SetOperation.wrap(mem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapUnionTest method checkSerVer1Handling.
@Test
public void checkSerVer1Handling() {
//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 v1mem1 = convertSerV3toSerV1(skMem1);
Memory v1mem2 = convertSerV3toSerV1(skMem2);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
union.update(v1mem1);
union.update(v1mem2);
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 HeapUnionTest method checkEmptySerVer2and3.
@Test
public //where the granted mem is larger than required
void checkEmptySerVer2and3() {
UpdateSketch usk1 = UpdateSketch.builder().build();
CompactSketch usk1c = usk1.compact(true, null);
byte[] skArr = usk1c.toByteArray();
byte[] skArr2 = Arrays.copyOf(skArr, skArr.length * 2);
WritableMemory v3mem1 = WritableMemory.wrap(skArr2);
Union union = SetOperation.builder().buildUnion();
union.update(v3mem1);
Memory v2mem1 = convertSerV3toSerV2(v3mem1);
WritableMemory v2mem2 = WritableMemory.wrap(new byte[16]);
v2mem1.copyTo(0, v2mem2, 0, 8);
union = SetOperation.builder().buildUnion();
union.update(v2mem2);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyIntersection.
@Test
public void heapifyIntersection() {
UpdateSketch us1 = UpdateSketch.builder().build();
us1.update(1);
us1.update(2);
UpdateSketch us2 = UpdateSketch.builder().build();
us2.update(2);
us2.update(3);
Intersection i1 = SetOperation.builder().buildIntersection();
i1.update(us1);
i1.update(us2);
Memory mem = Memory.wrap(ByteBuffer.wrap(i1.toByteArray()).asReadOnlyBuffer());
Intersection i2 = (Intersection) SetOperation.heapify(mem);
i2.update(us1);
Assert.assertEquals(i2.getResult().getEstimate(), 1.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method heapifyCompactOrderedSketch.
@Test
public void heapifyCompactOrderedSketch() {
UpdateSketch updateSketch = UpdateSketch.builder().build();
updateSketch.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact().toByteArray()).asReadOnlyBuffer());
Sketch sketch = Sketch.heapify(mem);
assertEquals(sketch.getEstimate(), 1.0);
}
Aggregations