use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapIntersectionTest method checkHeapifyNullEmpty.
@Test
public void checkHeapifyNullEmpty() {
Intersection inter1, inter2;
//virgin
inter1 = SetOperation.builder().buildIntersection();
byte[] byteArray = inter1.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
inter2 = (Intersection) SetOperation.heapify(srcMem);
//inter2 is in virgin state, empty = false
//A virgin intersection intersected with null => empty = true;
inter1.update(null);
//update the byteArray
byteArray = inter1.toByteArray();
srcMem = Memory.wrap(byteArray);
inter2 = (Intersection) SetOperation.heapify(srcMem);
CompactSketch comp = inter2.getResult(true, null);
assertEquals(comp.getRetainedEntries(false), 0);
assertTrue(comp.isEmpty());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class HeapIntersectionTest method checkHeapifyNullEmpty2.
@Test
public void checkHeapifyNullEmpty2() {
int lgK = 5;
int k = 1 << lgK;
Intersection inter1, inter2;
UpdateSketch sk1;
//virgin
inter1 = SetOperation.builder().buildIntersection();
byte[] byteArray = inter1.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
inter2 = (Intersection) SetOperation.heapify(srcMem);
//inter2 is in virgin state
sk1 = UpdateSketch.builder().setP((float) .005).setFamily(Family.QUICKSELECT).setNominalEntries(k).build();
sk1.update(1);
//A virgin intersection (empty = false) intersected with a not-empty zero cache sketch
//remains empty = false!
inter1.update(sk1);
byteArray = inter1.toByteArray();
srcMem = Memory.wrap(byteArray);
inter2 = (Intersection) SetOperation.heapify(srcMem);
CompactSketch comp = inter2.getResult(true, null);
assertEquals(comp.getRetainedEntries(false), 0);
assertFalse(comp.isEmpty());
}
use of com.yahoo.memory.Memory in project sketches-core by DataSketches.
the class ForwardCompatibilityTest method checkSerVer1_1Value.
@Test
public void checkSerVer1_1Value() {
byte[] byteArray = new byte[32];
WritableMemory mem = WritableMemory.wrap(byteArray);
mem.putByte(0, (byte) 3);
//SerVer
mem.putByte(1, (byte) 1);
//byte 2 Sketch Type, now Family
//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 = 1
mem.putInt(8, 1);
mem.putLong(16, Long.MAX_VALUE);
long[] longArrIn = new long[2];
longArrIn[0] = 1;
long hash = hash(longArrIn, 0)[0] >>> 1;
mem.putLong(24, hash);
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);
assertEquals(sketch.getEstimate(), 1.0);
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_8Bytes.
@Test
public void checkSerVer2_8Bytes() {
byte[] byteArray = new byte[8];
WritableMemory mem = WritableMemory.wrap(byteArray);
//mdLongs, RR = 0
mem.putByte(0, (byte) 1);
//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
mem.putByte(5, (byte) 2);
short seedHash = Util.computeSeedHash(Util.DEFAULT_UPDATE_SEED);
mem.putShort(6, seedHash);
//mem.putInt(8, 0); //curCount = 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 HeapAlphaSketchTest method checkHeapifyByteArrayEstimating.
@Test
public void checkHeapifyByteArrayEstimating() {
int k = 4096;
int u = 2 * 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);
double uskEst = usk.getEstimate();
double uskLB = usk.getLowerBound(2);
double uskUB = usk.getUpperBound(2);
assertEquals(usk.isEstimationMode(), true);
byte[] byteArray = usk.toByteArray();
Memory srcMem = Memory.wrap(byteArray);
UpdateSketch usk2 = (UpdateSketch) Sketch.heapify(srcMem, seed);
assertEquals(usk2.getEstimate(), uskEst);
assertEquals(usk2.getLowerBound(2), uskLB);
assertEquals(usk2.getUpperBound(2), uskUB);
assertEquals(usk2.isEmpty(), false);
assertEquals(usk2.isEstimationMode(), true);
assertEquals(usk2.getClass().getSimpleName(), usk.getClass().getSimpleName());
}
Aggregations