Search in sources :

Example 86 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method wrapCompactSketch.

@Test
public void wrapCompactSketch() {
    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    s1.update(1);
    s1.update(2);
    // Memory mem = Memory.wrap(ByteBuffer.wrap(s1.compact().toByteArray())
    // .asReadOnlyBuffer().order(ByteOrder.nativeOrder())););
    final Memory mem = Memory.wrap(s1.compact().toByteArray());
    // compact, so this is ok
    final DoublesSketch s2 = DoublesSketch.wrap(mem);
    Assert.assertEquals(s2.getMinValue(), 1.0);
    Assert.assertEquals(s2.getMaxValue(), 2.0);
    Assert.assertEquals(s2.getN(), 2);
}
Also used : Memory(org.apache.datasketches.memory.Memory) Test(org.testng.annotations.Test)

Example 87 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class ReadOnlyMemoryTest method heapifySparseSketch.

@Test
public void heapifySparseSketch() {
    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
    s1.update(1);
    s1.update(2);
    Memory mem = Memory.wrap(s1.toByteArray(false));
    DoublesSketch s2 = DoublesSketch.heapify(mem);
    Assert.assertEquals(s2.getMinValue(), 1.0);
    Assert.assertEquals(s2.getMaxValue(), 2.0);
}
Also used : Memory(org.apache.datasketches.memory.Memory) Test(org.testng.annotations.Test)

Example 88 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class DirectCompactDoublesSketchTest method wrapEmptyCompactSketch.

@Test
public void wrapEmptyCompactSketch() {
    final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact();
    final Memory mem = Memory.wrap(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder()));
    final DoublesSketch s2 = DoublesSketch.wrap(mem);
    assertTrue(s2.isEmpty());
    assertEquals(s2.getN(), 0);
    assertTrue(Double.isNaN(s2.getMinValue()));
    assertTrue(Double.isNaN(s2.getMaxValue()));
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 89 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class DirectCompactDoublesSketchTest method wrapFromUpdateSketch.

@Test(expectedExceptions = SketchesArgumentException.class)
public void wrapFromUpdateSketch() {
    final int k = 4;
    final int n = 27;
    final UpdateDoublesSketch qs = HeapUpdateDoublesSketchTest.buildAndLoadQS(k, n);
    final byte[] qsBytes = qs.toByteArray();
    final Memory qsMem = Memory.wrap(qsBytes);
    DirectCompactDoublesSketch.wrapInstance(qsMem);
    fail();
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 90 with Memory

use of org.apache.datasketches.memory.Memory in project sketches-core by DataSketches.

the class DirectCompactDoublesSketchTest method wrapFromCompactSketch.

@Test
public void wrapFromCompactSketch() {
    final int k = 8;
    final int n = 177;
    // assuming ordered inserts
    final DirectCompactDoublesSketch qs = buildAndLoadDCQS(k, n);
    final byte[] qsBytes = qs.toByteArray();
    final Memory qsMem = Memory.wrap(qsBytes);
    final DirectCompactDoublesSketch compactQs = DirectCompactDoublesSketch.wrapInstance(qsMem);
    DoublesSketchTest.testSketchEquality(qs, compactQs);
    assertEquals(qsBytes.length, compactQs.getStorageBytes());
    final double[] combinedBuffer = compactQs.getCombinedBuffer();
    assertEquals(combinedBuffer.length, compactQs.getCombinedBufferItemCapacity());
}
Also used : Memory(org.apache.datasketches.memory.Memory) WritableMemory(org.apache.datasketches.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

Memory (org.apache.datasketches.memory.Memory)213 Test (org.testng.annotations.Test)180 WritableMemory (org.apache.datasketches.memory.WritableMemory)164 SketchesArgumentException (org.apache.datasketches.SketchesArgumentException)17 ArrayOfLongsSerDe (org.apache.datasketches.ArrayOfLongsSerDe)14 SketchesReadOnlyException (org.apache.datasketches.SketchesReadOnlyException)11 File (java.io.File)10 ArrayOfStringsSerDe (org.apache.datasketches.ArrayOfStringsSerDe)10 Util.getResourceFile (org.apache.datasketches.Util.getResourceFile)10 MapHandle (org.apache.datasketches.memory.MapHandle)10 WritableHandle (org.apache.datasketches.memory.WritableHandle)6 SharedLocal (org.apache.datasketches.theta.ConcurrentHeapQuickSelectSketchTest.SharedLocal)3 ArrayOfNumbersSerDe (org.apache.datasketches.ArrayOfNumbersSerDe)2 CloseableIterator (org.apache.druid.java.util.common.parsers.CloseableIterator)2 IntIterator (it.unimi.dsi.fastutil.ints.IntIterator)1 HashSet (java.util.HashSet)1 Family (org.apache.datasketches.Family)1 SketchesStateException (org.apache.datasketches.SketchesStateException)1 CompressedState.importFromMemory (org.apache.datasketches.cpc.CompressedState.importFromMemory)1 DefaultMemoryRequestServer (org.apache.datasketches.memory.DefaultMemoryRequestServer)1