Search in sources :

Example 46 with WritableHandle

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) {
    }
}
Also used : WritableHandle(org.apache.datasketches.memory.WritableHandle) Test(org.testng.annotations.Test)

Example 47 with WritableHandle

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) {
    }
}
Also used : WritableHandle(org.apache.datasketches.memory.WritableHandle) Test(org.testng.annotations.Test)

Aggregations

WritableHandle (org.apache.datasketches.memory.WritableHandle)47 Test (org.testng.annotations.Test)44 WritableMemory (org.apache.datasketches.memory.WritableMemory)38 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)27 SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)24 DefaultMemoryRequestServer (org.apache.datasketches.memory.DefaultMemoryRequestServer)7 Memory (org.apache.datasketches.memory.Memory)6 HashSet (java.util.HashSet)1 SketchesStateException (org.apache.datasketches.SketchesStateException)1