Search in sources :

Example 1 with Memory

use of com.yahoo.memory.Memory in project druid by druid-io.

the class SketchBufferAggregator method getUnion.

//Note that this is not threadsafe and I don't think it needs to be
private Union getUnion(ByteBuffer buf, int position) {
    Union union = unions.get(position);
    if (union == null) {
        Memory mem = new MemoryRegion(nm, position, maxIntermediateSize);
        union = (Union) SetOperation.wrap(mem);
        unions.put(position, union);
    }
    return union;
}
Also used : Memory(com.yahoo.memory.Memory) NativeMemory(com.yahoo.memory.NativeMemory) MemoryRegion(com.yahoo.memory.MemoryRegion) Union(com.yahoo.sketches.theta.Union)

Example 2 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ForwardCompatibilityTest method checkSerVer2_32Bytes_1Value.

@Test
public void checkSerVer2_32Bytes_1Value() {
    byte[] byteArray = new byte[32];
    WritableMemory mem = WritableMemory.wrap(byteArray);
    //mdLongs, RF (RR) = 0
    mem.putByte(0, (byte) 3);
    //SerVer
    mem.putByte(1, (byte) 2);
    //SketchType = SetSketch
    mem.putByte(2, (byte) 3);
    //byte 3 lgNomLongs not used w SetSketch
    //byte 4 lgArrLongs not used w SetSketch
    //byte 5 Flags: b0: BigEnd, b1: ReadOnly, b2: Empty, b3: NoRebuild, b4, Unordered
    //Flags = ReadOnly
    mem.putByte(5, (byte) 2);
    short seedHash = Util.computeSeedHash(Util.DEFAULT_UPDATE_SEED);
    mem.putShort(6, seedHash);
    //curCount = 0
    mem.putInt(8, 0);
    mem.putLong(16, Long.MAX_VALUE);
    Memory srcMem = Memory.wrap(byteArray);
    Sketch sketch = Sketch.heapify(srcMem);
    assertEquals(sketch.isEmpty(), false);
    assertEquals(sketch.isEstimationMode(), false);
    assertEquals(sketch.isDirect(), false);
    assertEquals(sketch.isCompact(), true);
    assertEquals(sketch.isOrdered(), true);
    String name = sketch.getClass().getSimpleName();
    assertEquals(name, "HeapCompactOrderedSketch");
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 3 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ForwardCompatibilityTest method checkSerVer1_24Bytes.

@Test
public void checkSerVer1_24Bytes() {
    byte[] byteArray = new byte[24];
    WritableMemory mem = WritableMemory.wrap(byteArray);
    //mdLongs
    mem.putByte(0, (byte) 3);
    //SerVer
    mem.putByte(1, (byte) 1);
    //SketchType = SetSketch
    mem.putByte(2, (byte) 3);
    //byte 3 lgNomLongs not used with SetSketch
    //byte 4 lgArrLongs not used with SetSketch
    //byte 5 lgRR not used with SetSketch
    //byte 6: Flags: b0: BigEnd, b1: ReadOnly
    mem.putByte(6, (byte) 2);
    //byte 7 Not used
    //curCount = 0
    mem.putInt(8, 0);
    mem.putLong(16, Long.MAX_VALUE);
    Memory srcMem = Memory.wrap(byteArray);
    Sketch sketch = Sketch.heapify(srcMem);
    assertEquals(sketch.isEmpty(), true);
    assertEquals(sketch.isEstimationMode(), false);
    assertEquals(sketch.isDirect(), false);
    assertEquals(sketch.isCompact(), true);
    assertEquals(sketch.isOrdered(), true);
    String name = sketch.getClass().getSimpleName();
    assertEquals(name, "HeapCompactOrderedSketch");
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 4 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class ForwardCompatibilityTest method checkSerVer2_24Bytes_1Value.

@Test
public void checkSerVer2_24Bytes_1Value() {
    byte[] byteArray = new byte[24];
    WritableMemory mem = WritableMemory.wrap(byteArray);
    //mdLongs, RF (RR) = 0
    mem.putByte(0, (byte) 2);
    //SerVer
    mem.putByte(1, (byte) 2);
    //SketchType = SetSketch
    mem.putByte(2, (byte) 3);
    //byte 3 lgNomLongs not used w SetSketch
    //byte 4 lgArrLongs not used w SetSketch
    //byte 5 Flags: b0: BigEnd, b1: ReadOnly, b2: Empty, b3: NoRebuild, b4, Unordered
    //Flags = ReadOnly
    mem.putByte(5, (byte) 2);
    short seedHash = Util.computeSeedHash(Util.DEFAULT_UPDATE_SEED);
    mem.putShort(6, seedHash);
    //curCount = 0
    mem.putInt(8, 0);
    //mem.putLong(16, Long.MAX_VALUE);
    Memory srcMem = Memory.wrap(byteArray);
    Sketch sketch = Sketch.heapify(srcMem);
    assertEquals(sketch.isEmpty(), false);
    assertEquals(sketch.isEstimationMode(), false);
    assertEquals(sketch.isDirect(), false);
    assertEquals(sketch.isCompact(), true);
    assertEquals(sketch.isOrdered(), true);
    String name = sketch.getClass().getSimpleName();
    assertEquals(name, "HeapCompactOrderedSketch");
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Example 5 with Memory

use of com.yahoo.memory.Memory in project sketches-core by DataSketches.

the class HeapAlphaSketchTest method checkHeapifyByteArrayExact.

@Test
public void checkHeapifyByteArrayExact() {
    int k = 512;
    int u = k;
    long seed = DEFAULT_UPDATE_SEED;
    UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setSeed(seed).setNominalEntries(k).build();
    for (int i = 0; i < u; i++) usk.update(i);
    int bytes = usk.getCurrentBytes(false);
    byte[] byteArray = usk.toByteArray();
    assertEquals(bytes, byteArray.length);
    Memory srcMem = Memory.wrap(byteArray);
    UpdateSketch usk2 = (UpdateSketch) Sketch.heapify(srcMem, seed);
    assertEquals(usk2.getEstimate(), u, 0.0);
    assertEquals(usk2.getLowerBound(2), u, 0.0);
    assertEquals(usk2.getUpperBound(2), u, 0.0);
    assertEquals(usk2.isEmpty(), false);
    assertEquals(usk2.isEstimationMode(), false);
    assertEquals(usk2.getClass().getSimpleName(), usk.getClass().getSimpleName());
    usk2.toString(true, true, 8, true);
}
Also used : Memory(com.yahoo.memory.Memory) WritableMemory(com.yahoo.memory.WritableMemory) Test(org.testng.annotations.Test)

Aggregations

Memory (com.yahoo.memory.Memory)141 Test (org.testng.annotations.Test)121 WritableMemory (com.yahoo.memory.WritableMemory)111 ArrayOfLongsSerDe (com.yahoo.sketches.ArrayOfLongsSerDe)11 ArrayOfStringsSerDe (com.yahoo.sketches.ArrayOfStringsSerDe)10 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)10 SketchesReadOnlyException (com.yahoo.sketches.SketchesReadOnlyException)6 MemoryRegion (com.yahoo.memory.MemoryRegion)2 NativeMemory (com.yahoo.memory.NativeMemory)2 ArrayOfNumbersSerDe (com.yahoo.sketches.ArrayOfNumbersSerDe)2 WritableDirectHandle (com.yahoo.memory.WritableDirectHandle)1 Util.checkIsCompactMemory (com.yahoo.sketches.quantiles.Util.checkIsCompactMemory)1 CompactSketch.createCompactSketch (com.yahoo.sketches.theta.CompactSketch.createCompactSketch)1 Union (com.yahoo.sketches.theta.Union)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1