use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest method checkMinReqBytes.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkMinReqBytes() {
int k = 16;
UpdateSketch s1 = Sketches.updateSketchBuilder().setNominalEntries(k).build();
for (int i = 0; i < 4 * k; i++) {
s1.update(i);
}
byte[] byteArray = s1.toByteArray();
byte[] badBytes = Arrays.copyOfRange(byteArray, 0, 24);
Memory mem = Memory.wrap(badBytes);
Sketch.heapify(mem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ReadOnlyMemoryTest method wrapCompactOrderedSketch.
@Test
public void wrapCompactOrderedSketch() {
UpdateSketch updateSketch = UpdateSketch.builder().build();
updateSketch.update(1);
Memory mem = Memory.wrap(ByteBuffer.wrap(updateSketch.compact().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 ReadOnlyMemoryTest method wrapIntersection.
@Test
public void wrapIntersection() {
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.wrap(mem);
Assert.assertEquals(i2.getResult().getEstimate(), 1.0);
boolean thrown = false;
try {
i2.update(us1);
} catch (SketchesReadOnlyException e) {
thrown = true;
}
Assert.assertTrue(thrown);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SetOperationTest method checkIsSameResource.
@Test
public void checkIsSameResource() {
int k = 16;
WritableMemory mem = WritableMemory.wrap(new byte[(k * 16) + 32]);
Memory cmem = Memory.wrap(new byte[8]);
Union union = Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(mem);
assertTrue(union.isSameResource(mem));
assertFalse(union.isSameResource(cmem));
Intersection inter = Sketches.setOperationBuilder().buildIntersection(mem);
assertTrue(inter.isSameResource(mem));
assertFalse(inter.isSameResource(cmem));
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SetOperationTest method checkIllegalSetOpHeapify.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkIllegalSetOpHeapify() {
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.heapify(mem);
}
Aggregations