use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DoublesUtilTest method checkCopyToHeap.
@Test
public void checkCopyToHeap() {
final int k = 128;
final int n = 400;
// HeapUpdateDoublesSketch
final HeapUpdateDoublesSketch huds = (HeapUpdateDoublesSketch) buildAndLoadQS(k, n);
final HeapUpdateDoublesSketch target1 = DoublesUtil.copyToHeap(huds);
DoublesSketchTest.testSketchEquality(huds, target1);
// DirectUpdateDoublesSketch
final WritableMemory mem1 = WritableMemory.wrap(huds.toByteArray());
final DirectUpdateDoublesSketch duds = (DirectUpdateDoublesSketch) UpdateDoublesSketch.wrap(mem1);
final HeapUpdateDoublesSketch target2 = DoublesUtil.copyToHeap(duds);
DoublesSketchTest.testSketchEquality(huds, duds);
DoublesSketchTest.testSketchEquality(duds, target2);
// HeapCompactDoublesSketch
final CompactDoublesSketch hcds = huds.compact();
final HeapUpdateDoublesSketch target3 = DoublesUtil.copyToHeap(hcds);
DoublesSketchTest.testSketchEquality(huds, hcds);
DoublesSketchTest.testSketchEquality(hcds, target3);
// DirectCompactDoublesSketch
final Memory mem2 = Memory.wrap(hcds.toByteArray());
final DirectCompactDoublesSketch dcds = (DirectCompactDoublesSketch) DoublesSketch.wrap(mem2);
final HeapUpdateDoublesSketch target4 = DoublesUtil.copyToHeap(dcds);
DoublesSketchTest.testSketchEquality(huds, dcds);
DoublesSketchTest.testSketchEquality(dcds, target4);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ForwardCompatibilityTest method getAndCheck.
private void getAndCheck(String ver, int n, double quantile) {
//make deterministic
DoublesSketch.rand.setSeed(131);
//create fileName
int k = 128;
double nf = 0.5;
String fileName = String.format("Qk%d_n%d_v%s.bin", k, n, ver);
println("fullName: " + fileName);
println("Old Median: " + quantile);
//create & Read File
File file = new File(getClass().getClassLoader().getResource(fileName).getFile());
byte[] byteArr2 = readFile(file);
Memory srcMem = Memory.wrap(byteArr2);
// heapify as update sketch
DoublesSketch qs2 = UpdateDoublesSketch.heapify(srcMem);
//Test the quantile
double q2 = qs2.getQuantile(nf);
println("New Median: " + q2);
Assert.assertEquals(q2, quantile, 0.0);
// same thing with compact sketch
qs2 = CompactDoublesSketch.heapify(srcMem);
//Test the quantile
q2 = qs2.getQuantile(nf);
println("New Median: " + q2);
Assert.assertEquals(q2, quantile, 0.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchTest method checkSerVer.
@Test
public void checkSerVer() {
UpdateSketch sketch = UpdateSketch.builder().setNominalEntries(1024).build();
byte[] sketchArray = sketch.toByteArray();
Memory mem = Memory.wrap(sketchArray);
int serVer = Sketch.getSerializationVersion(mem);
assertEquals(serVer, 3);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchTest method checkHeapifyFamilyExcep.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifyFamilyExcep() {
int k = 512;
Union union = SetOperation.builder().setNominalEntries(k).buildUnion();
byte[] byteArray = union.toByteArray();
Memory mem = Memory.wrap(byteArray);
//Improper use
Sketch.heapify(mem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class SketchesTest method checkSetOpMethods.
@Test
public void checkSetOpMethods() {
int k = 1024;
Memory mem1 = getCompactSketch(k, 0, k);
Memory mem2 = getCompactSketch(k, k / 2, 3 * k / 2);
SetOperationBuilder bldr = setOperationBuilder();
Union union = bldr.setNominalEntries(2 * k).buildUnion();
union.update(mem1);
CompactSketch cSk = union.getResult(true, null);
assertEquals((int) cSk.getEstimate(), k);
union.update(mem2);
cSk = union.getResult(true, null);
assertEquals((int) cSk.getEstimate(), 3 * k / 2);
byte[] ubytes = union.toByteArray();
WritableMemory uMem = WritableMemory.wrap(ubytes);
Union union2 = (Union) heapifySetOperation(uMem);
cSk = union2.getResult(true, null);
assertEquals((int) cSk.getEstimate(), 3 * k / 2);
union2 = (Union) heapifySetOperation(uMem, Util.DEFAULT_UPDATE_SEED);
cSk = union2.getResult(true, null);
assertEquals((int) cSk.getEstimate(), 3 * k / 2);
union2 = (Union) wrapSetOperation(uMem);
cSk = union2.getResult(true, null);
assertEquals((int) cSk.getEstimate(), 3 * k / 2);
union2 = (Union) wrapSetOperation(uMem, Util.DEFAULT_UPDATE_SEED);
cSk = union2.getResult(true, null);
assertEquals((int) cSk.getEstimate(), 3 * k / 2);
int serVer = getSerializationVersion(uMem);
assertEquals(serVer, 3);
}
Aggregations