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;
}
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");
}
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");
}
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");
}
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);
}
Aggregations