@Test public void checkEmptyUnion() { final DoublesUnionImpl union = DoublesUnionImpl.heapInstance(128); final DoublesSketch sk = union.getResult(); assertNotNull(sk); final byte[] bytes = union.toByteArray(); assertEquals(bytes.length, 8); // final String s = union.toString(); assertNotNull(s); }
/** * Returns a Heap Union object that has been initialized with the data from the given sketch. * @param sketch A DoublesSketch to be used as a source of data only and will not be modified. * @return a DoublesUnion object */ public static DoublesUnion heapify(final DoublesSketch sketch) { return DoublesUnionImpl.heapifyInstance(sketch); }
@Override public void update(final DoublesSketch sketchIn) { gadget_ = updateLogic(maxK_, gadget_, sketchIn); }
/** * Returns a new empty Union object with the current configuration of this Builder. * @return a Union object */ public DoublesUnion build() { return DoublesUnionImpl.heapInstance(bMaxK); }
/** * Returns a empty Heap DoublesUnion object. * @param maxK determines the accuracy and size of the union and is a maximum value. * The effective <i>k</i> can be smaller due to unions with smaller <i>k</i> sketches. * It is recommended that <i>maxK</i> be a power of 2 to enable unioning of sketches with * different values of <i>k</i>. * @return a new DoublesUnionImpl on the Java heap */ static DoublesUnionImpl heapInstance(final int maxK) { return new DoublesUnionImpl(maxK); }
/** * Returns an updatable Union object that wraps off-heap data of the given memory image of * a sketch. The data structures of the Union remain off-heap. * * @param mem A memory region to be used as the data structure for the sketch * and will be modified. * @return a Union object */ public static DoublesUnion wrap(final WritableMemory mem) { return DoublesUnionImpl.wrapInstance(mem); }
/** * Returns a new empty Union object with the current configuration of this Builder * and the specified backing destination Memory store. * @param dstMem the destination memory * @return a Union object */ public DoublesUnion build(final WritableMemory dstMem) { return DoublesUnionImpl.directInstance(bMaxK, dstMem); }
@Test public void checkUnionNulls() { final DoublesUnion union = DoublesUnionImpl.heapInstance(128); final DoublesSketch sk1 = union.getResultAndReset(); final DoublesSketch sk2 = union.getResultAndReset(); assertNull(sk1); assertNull(sk2); union.update(sk2); final DoublesSketch sk3 = union.getResultAndReset(); assertNull(sk3); }
/** * Returns a empty DoublesUnion object that refers to the given direct, off-heap Memory, * which will be initialized to the empty state. * * @param maxK determines the accuracy and size of the union and is a maximum value. * The effective <i>k</i> can be smaller due to unions with smaller <i>k</i> sketches. * It is recommended that <i>maxK</i> be a power of 2 to enable unioning of sketches with * different values of <i>k</i>. * @param dstMem the Memory to be used by the sketch * @return a DoublesUnion object */ static DoublesUnionImpl directInstance(final int maxK, final WritableMemory dstMem) { final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.newInstance(maxK, dstMem); final DoublesUnionImpl union = new DoublesUnionImpl(maxK); union.maxK_ = maxK; union.gadget_ = sketch; return union; }
/** * Returns an updatable Union object that wraps off-heap data of the given memory image of * a sketch. The data structures of the Union remain off-heap. * * @param mem A memory region to be used as the data structure for the sketch * and will be modified. * @return a Union object * @deprecated moved to DoublesUnion */ @Deprecated public static DoublesUnion wrap(final WritableMemory mem) { return DoublesUnionImpl.wrapInstance(mem); }
/** * Returns a new empty Union object with the current configuration of this Builder * and the specified backing destination Memory store. * @param dstMem the destination memory * @return a Union object */ public DoublesUnion build(final WritableMemory dstMem) { return DoublesUnionImpl.directInstance(bMaxK, dstMem); }
/** * Returns a Heap Union object that has been initialized with the data from the given memory * image of a sketch. * * @param srcMem A memory image of a DoublesSketch to be used as a source of data, * but will not be modified. * @return a Union object */ public static DoublesUnion heapify(final Memory srcMem) { return DoublesUnionImpl.heapifyInstance(srcMem); }
@Override public void update(final Memory mem) { gadget_ = updateLogic(maxK_, gadget_, HeapUpdateDoublesSketch.heapifyInstance(mem)); }
@Test public void checkUnion7Direct() { final DoublesUnion union = DoublesUnionImpl.heapInstance(16); final DoublesSketch skEst = buildAndLoadDQS(32, 64); //other is bigger, est union.update(skEst); final DoublesSketch result = union.getResult(); assertEquals(result.getMaxValue(), 64, 0.0); assertEquals(result.getMinValue(), 1.0, 0.0); // println(skEst.toString(true, true)); // println(union.toString(true, true)); }
/** * Returns an updatable Union object that wraps off-heap data structure of the given memory * image of a non-compact DoublesSketch. The data structures of the Union remain off-heap. * * @param mem A memory image of a non-compact DoublesSketch to be used as the data * structure for the union and will be modified. * @return a Union object */ static DoublesUnionImpl wrapInstance(final WritableMemory mem) { final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.wrapInstance(mem); final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK()); union.gadget_ = sketch; return union; }
/** * Returns an updatable Union object that wraps off-heap data of the given memory image of * a sketch. The data structures of the Union remain off-heap. * * @param mem A memory region to be used as the data structure for the sketch * and will be modified. * @return a Union object */ public static DoublesUnion wrap(final WritableMemory mem) { return DoublesUnionImpl.wrapInstance(mem); }
/** * Returns a Heap Union object that has been initialized with the data from the given sketch. * @param sketch A DoublesSketch to be used as a source of data only and will not be modified. * @return a DoublesUnion object * @deprecated moved to DoublesUnion */ @Deprecated public static DoublesUnion heapify(final DoublesSketch sketch) { return DoublesUnionImpl.heapifyInstance(sketch); }
@Test public void checkUnionUpdateLogic() { final HeapUpdateDoublesSketch qs1 = null; final HeapUpdateDoublesSketch qs2 = (HeapUpdateDoublesSketch) buildAndLoadQS(256, 0); DoublesUnionImpl.updateLogic(256, qs1, qs2); //null, empty DoublesUnionImpl.updateLogic(256, qs2, qs1); //empty, null qs2.update(1); //no longer empty final DoublesSketch result = DoublesUnionImpl.updateLogic(256, qs2, qs1); //valid, null assertEquals(result.getMaxValue(), result.getMinValue(), 0.0); }
@Test public void checkUnion7() { final DoublesUnion union = DoublesUnionImpl.heapInstance(16); final DoublesSketch skEst = buildAndLoadQS(32, 64); //other is bigger, est union.update(skEst); println(skEst.toString(true, true)); println(union.toString(true, true)); final DoublesSketch result = union.getResult(); assertEquals(result.getMaxValue(), 64, 0.0); assertEquals(result.getMinValue(), 1.0, 0.0); }
/** * Returns a Heap DoublesUnion object that has been initialized with the data from the given * Memory image of a DoublesSketch. The srcMem object will not be modified and a reference to * it is not retained. The <i>maxK</i> of the resulting union will be that obtained from * the sketch Memory image. * * @param srcMem a Memory image of a quantiles DoublesSketch * @return a DoublesUnion object */ static DoublesUnionImpl heapifyInstance(final Memory srcMem) { final HeapUpdateDoublesSketch sketch = HeapUpdateDoublesSketch.heapifyInstance(srcMem); final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK()); union.gadget_ = sketch; return union; }