use of org.apache.datasketches.memory.WritableHandle in project sketches-core by DataSketches.
the class HeapifyWrapSerVer1and2Test method checkWrapSketchAssumedDefaultSeed.
@Test
public void checkWrapSketchAssumedDefaultSeed() {
final int k = 64;
final long seed = DEFAULT_UPDATE_SEED;
final short seedHash = Util.computeSeedHash(seed);
UpdateSketch sv3usk = UpdateSketch.builder().setNominalEntries(k).setSeed(seed).build();
for (int i = 0; i < k; i++) {
sv3usk.update(i);
}
CompactSketch sv3cskResult;
WritableHandle wh;
CompactSketch sv3csk = sv3usk.compact();
// SV3 test
wh = putOffHeap(Memory.wrap(sv3csk.toByteArray()));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable());
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertTrue(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
// SV2 test
wh = putOffHeap(BackwardConversions.convertSerVer3toSerVer2(sv3csk, seed));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable());
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertFalse(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
// SV1 test
wh = putOffHeap(BackwardConversions.convertSerVer3toSerVer1(sv3csk));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable());
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertFalse(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
}
use of org.apache.datasketches.memory.WritableHandle in project sketches-core by DataSketches.
the class HeapifyWrapSerVer1and2Test method checkWrapSketchGivenDifferentSeed.
@Test
public void checkWrapSketchGivenDifferentSeed() {
final int k = 64;
final long seed = 128L;
final short seedHash = Util.computeSeedHash(seed);
UpdateSketch sv3usk = UpdateSketch.builder().setNominalEntries(k).setSeed(seed).build();
for (int i = 0; i < k; i++) {
sv3usk.update(i);
}
CompactSketch sv3cskResult;
WritableHandle wh;
CompactSketch sv3csk = sv3usk.compact();
// SV3 test
wh = putOffHeap(Memory.wrap(sv3csk.toByteArray()));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable(), seed);
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertTrue(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
// SV2 test
wh = putOffHeap(BackwardConversions.convertSerVer3toSerVer2(sv3csk, seed));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable(), seed);
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertFalse(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
// SV1 test
wh = putOffHeap(BackwardConversions.convertSerVer3toSerVer1(sv3csk));
sv3cskResult = (CompactSketch) Sketches.wrapSketch(wh.getWritable(), seed);
assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate());
assertEquals(sv3cskResult.getSeedHash(), seedHash);
assertFalse(sv3cskResult.isDirect());
try {
wh.close();
} catch (Exception e) {
}
}
Aggregations