Search in sources :

Example 21 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkIllegalHashUpdate.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void checkIllegalHashUpdate() {
    int lgK = 4;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    shared.hashUpdate(1);
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 22 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkDQStoCompactEmptyForms.

@Test
public void checkDQStoCompactEmptyForms() {
    int lgK = 9;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    // empty
    // exercise toString
    local.toString(false, true, 0, false);
    assertEquals(local.getClass().getSimpleName(), "ConcurrentHeapThetaBuffer");
    double localEst = local.getEstimate();
    double localLB = local.getLowerBound(2);
    double localUB = local.getUpperBound(2);
    assertFalse(local.isEstimationMode());
    // compact form
    int bytes = local.getCompactBytes();
    assertEquals(bytes, 8);
    byte[] memArr2 = new byte[bytes];
    WritableMemory mem2 = WritableMemory.writableWrap(memArr2);
    CompactSketch csk2 = shared.compact(false, mem2);
    assertEquals(csk2.getEstimate(), localEst);
    assertEquals(csk2.getLowerBound(2), localLB);
    assertEquals(csk2.getUpperBound(2), localUB);
    assertTrue(csk2.isEmpty());
    assertFalse(csk2.isEstimationMode());
    assertTrue(csk2.isOrdered());
    CompactSketch csk3 = shared.compact(true, mem2);
    csk3.toString(false, true, 0, false);
    csk3.toString();
    assertEquals(csk3.getEstimate(), localEst);
    assertEquals(csk3.getLowerBound(2), localLB);
    assertEquals(csk3.getUpperBound(2), localUB);
    assertTrue(csk3.isEmpty());
    assertFalse(csk3.isEstimationMode());
    assertTrue(csk2.isOrdered());
}
Also used : WritableMemory(org.apache.datasketches.memory.WritableMemory) SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 23 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkHeapifyByteArrayEstimating.

@Test
public void checkHeapifyByteArrayEstimating() {
    int lgK = 12;
    int k = 1 << lgK;
    int u = 2 * k;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    double uskEst = local.getEstimate();
    double uskLB = local.getLowerBound(2);
    double uskUB = local.getUpperBound(2);
    assertEquals(local.isEstimationMode(), true);
    byte[] serArr = shared.toByteArray();
    Memory srcMem = Memory.wrap(serArr);
    Sketch recoveredShared = Sketch.heapify(srcMem);
    // reconstruct to Native/Direct
    final int bytes = Sketch.getMaxUpdateSketchBytes(k);
    final WritableMemory wmem = WritableMemory.allocate(bytes);
    shared = sl.bldr.buildSharedFromSketch((UpdateSketch) recoveredShared, wmem);
    UpdateSketch local2 = sl.bldr.buildLocal(shared);
    assertEquals(local2.getEstimate(), uskEst);
    assertEquals(local2.getLowerBound(2), uskLB);
    assertEquals(local2.getUpperBound(2), uskUB);
    assertEquals(local2.isEmpty(), false);
    assertEquals(local2.isEstimationMode(), true);
    assertEquals(recoveredShared.getClass().getSimpleName(), "HeapQuickSelectSketch");
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) WritableMemory(org.apache.datasketches.memory.WritableMemory) SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 24 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkHeapifyByteArrayExact.

@Test
public void checkHeapifyByteArrayExact() {
    int lgK = 9;
    int k = 1 << lgK;
    boolean useMem = true;
    SharedLocal sl = new SharedLocal(lgK, lgK, useMem);
    UpdateSketch shared = sl.shared;
    UpdateSketch local = sl.local;
    for (int i = 0; i < k; i++) {
        local.update(i);
    }
    waitForBgPropagationToComplete(shared);
    byte[] serArr = shared.toByteArray();
    Memory srcMem = Memory.wrap(serArr);
    Sketch recoveredShared = Sketch.heapify(srcMem);
    // reconstruct to Native/Direct
    final int bytes = Sketch.getMaxUpdateSketchBytes(k);
    final WritableMemory wmem = WritableMemory.allocate(bytes);
    shared = sl.bldr.buildSharedFromSketch((UpdateSketch) recoveredShared, wmem);
    UpdateSketch local2 = sl.bldr.buildLocal(shared);
    assertEquals(local2.getEstimate(), k, 0.0);
    assertEquals(local2.getLowerBound(2), k, 0.0);
    assertEquals(local2.getUpperBound(2), k, 0.0);
    assertEquals(local2.isEmpty(), false);
    assertEquals(local2.isEstimationMode(), false);
    assertEquals(recoveredShared.getClass().getSimpleName(), "HeapQuickSelectSketch");
    // Run toString just to make sure that we can pull out all of the relevant information.
    // That is, this is being run for its side-effect of accessing things.
    // If something is wonky, it will generate an exception and fail the test.
    local2.toString(true, true, 8, true);
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) WritableMemory(org.apache.datasketches.memory.WritableMemory) SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Example 25 with SharedLocal

use of org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal in project sketches-core by DataSketches.

the class ConcurrentDirectQuickSelectSketchTest method checkResizeInBigMem.

// checks Alex's bug where lgArrLongs > lgNomLongs +1.
@Test
public void checkResizeInBigMem() {
    int lgK = 14;
    int u = 1 << 20;
    boolean useMem = true;
    // mem is 8X larger than needed
    SharedLocal sl = new SharedLocal(lgK, lgK, SEED, useMem, true, 8);
    UpdateSketch local = sl.local;
    for (int i = 0; i < u; i++) {
        local.update(i);
    }
}
Also used : SharedLocal(org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal) Test(org.testng.annotations.Test)

Aggregations

SharedLocal (org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal)26 Test (org.testng.annotations.Test)26 WritableMemory (org.apache.datasketches.memory.WritableMemory)6 Memory (org.apache.datasketches.memory.Memory)3