use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DirectUnionTest method checkUpdateMemorySpecialCases.
@Test
public void checkUpdateMemorySpecialCases() {
//4096
int lgK = 12;
int k = 1 << lgK;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
CompactSketch usk1c = usk1.compact(true, null);
WritableMemory v3mem1 = WritableMemory.wrap(usk1c.toByteArray());
Memory v1mem1 = convertSerV3toSerV1(v3mem1);
//union memory
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v1mem1);
CompactSketch cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), 0.0, 0.0);
Memory v2mem1 = convertSerV3toSerV2(v3mem1);
//union memory
uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v2mem1);
cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), 0.0, 0.0);
//union memory
uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v3mem1);
cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), 0.0, 0.0);
//union memory
uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
v3mem1 = null;
union.update(v3mem1);
cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), 0.0, 0.0);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class DirectUnionTest method checkSerVer2Handling.
@Test
public void checkSerVer2Handling() {
//4096
int lgK = 12;
int k = 1 << lgK;
int u1 = 2 * k;
//smaller exact sketch forces early stop
int u2 = 1024;
int totU = u1 + u2;
UpdateSketch usk1 = UpdateSketch.builder().setNominalEntries(k).build();
UpdateSketch usk2 = UpdateSketch.builder().setNominalEntries(k).build();
//2*k
for (int i = 0; i < u1; i++) usk1.update(i);
//2*k + 1024 no overlap
for (int i = u1; i < totU; i++) usk2.update(i);
WritableMemory skMem1 = WritableMemory.wrap(usk1.compact(true, null).toByteArray());
WritableMemory skMem2 = WritableMemory.wrap(usk2.compact(true, null).toByteArray());
Memory v2mem1 = convertSerV3toSerV2(skMem1);
Memory v2mem2 = convertSerV3toSerV2(skMem2);
//union memory
WritableMemory uMem = WritableMemory.wrap(new byte[getMaxUnionBytes(k)]);
Union union = SetOperation.builder().setNominalEntries(k).buildUnion(uMem);
union.update(v2mem1);
union.update(v2mem2);
CompactSketch cOut = union.getResult(true, null);
assertEquals(cOut.getEstimate(), totU, .05 * k);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ForwardCompatibilityTest method checkSerVer1_32Bytes_tooSmall.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkSerVer1_32Bytes_tooSmall() {
byte[] byteArray = new byte[32];
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 = 2
mem.putInt(8, 2);
mem.putLong(16, Long.MAX_VALUE);
Memory srcMem = Memory.wrap(byteArray);
Sketch.heapify(srcMem);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest method checkHeapifySeedConflict.
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkHeapifySeedConflict() {
int k = 512;
long seed1 = 1021;
long seed2 = DEFAULT_UPDATE_SEED;
UpdateSketch usk = UpdateSketch.builder().setFamily(fam_).setSeed(seed1).setNominalEntries(k).build();
byte[] byteArray = usk.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
Sketch.heapify(srcMem, seed2);
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapQuickSelectSketchTest 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.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