File tree Expand file tree Collapse file tree
main/java/org/apache/datasketches/quantiles
test/java/org/apache/datasketches/quantiles Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,6 +154,19 @@ public static DoublesSketch heapify(final MemorySegment srcSeg) {
154154 * Wrap this sketch around the given updatable MemorySegment image of a DoublesSketch, compact or updatable.
155155 *
156156 * @param srcSeg the given MemorySegment image of a DoublesSketch that may have data
157+ * @return a sketch that wraps the given srcSeg in read-only mode.
158+ */
159+ public static DoublesSketch wrap (final MemorySegment srcSeg ) {
160+ if (checkIsMemorySegmentCompact (srcSeg )) {
161+ return DirectCompactDoublesSketch .wrapInstance (srcSeg );
162+ }
163+ return DirectUpdateDoublesSketch .wrapInstance (srcSeg , null );
164+ }
165+
166+ /**
167+ * Wrap this sketch around the given updatable MemorySegment image of a DoublesSketch, compact or updatable.
168+ *
169+ * @param srcSeg the given MemorySegment image of a DoublesSketch that may have data.
157170 * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand.
158171 * Otherwise, it can be null and the default MemorySegmentRequest will be used.
159172 * @return a sketch that wraps the given srcSeg in read-only mode.
Original file line number Diff line number Diff line change @@ -60,15 +60,24 @@ public static DoublesUnion heapify(final MemorySegment srcSeg) {
6060 }
6161
6262 /**
63- * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a sketch.
64- * The data structures of the Union remain in the MemorySegment.
63+ * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a DoublesSketch.
6564 *
66- * @param srcSeg A MemorySegment to be used as the data structure for the sketch and will be modified.
65+ * @param srcSeg A MemorySegment image of an updatable DoublesSketch to be used as the data structure for the union and will be modified.
66+ * @return a Union object
67+ */
68+ public static DoublesUnion wrap (final MemorySegment srcSeg ) {
69+ return DoublesUnionImpl .wrapInstance (srcSeg , null );
70+ }
71+
72+ /**
73+ * Returns an updatable Union object that wraps the given MemorySegment that contains an image of a DoublesSketch.
74+ *
75+ * @param srcSeg A MemorySegment sketch to be used as the data structure for the union and will be modified.
6776 * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand.
6877 * Otherwise, it can be null and the default MemorySegmentRequest will be used.
6978 * @return a Union object
7079 */
71- public static DoublesUnion writableWrap (final MemorySegment srcSeg , final MemorySegmentRequest mSegReq ) {
80+ public static DoublesUnion wrap (final MemorySegment srcSeg , final MemorySegmentRequest mSegReq ) {
7281 return DoublesUnionImpl .wrapInstance (srcSeg , mSegReq );
7382 }
7483
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ static DoublesUnionImpl heapifyInstance(final MemorySegment srcSeg) {
114114 * Returns an updatable Union object that wraps the data of the given MemorySegment
115115 * image of a updatable DoublesSketch. The data of the Union will remain in the MemorySegment.
116116 *
117- * @param srcSeg A writable MemorySegment image of a updatable DoublesSketch to be used as data for the union.
117+ * @param srcSeg A MemorySegment image of an updatable DoublesSketch to be used as the data structure for the union and will be modified .
118118 * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand.
119119 * Otherwise, it can be null and the default MemorySegmentRequest will be used.
120120 * @return a Union object
Original file line number Diff line number Diff line change @@ -33,6 +33,16 @@ public abstract class UpdateDoublesSketch extends DoublesSketch {
3333 super (k );
3434 }
3535
36+ /**
37+ * Wrap this sketch around the given MemorySegment image of an UpdateDoublesSketch.
38+ *
39+ * @param srcSeg the given MemorySegment image of an UpdateDoublesSketch and must not be null.
40+ * @return a sketch that wraps the given srcSeg
41+ */
42+ public static UpdateDoublesSketch wrap (final MemorySegment srcSeg ) {
43+ return DirectUpdateDoublesSketch .wrapInstance (srcSeg , null );
44+ }
45+
3646 /**
3747 * Wrap this sketch around the given MemorySegment image of an UpdateDoublesSketch.
3848 *
Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ public void wrapUnionFromHeap() {
226226 s1 .update (2 );
227227 final MemorySegment seg = MemorySegment .ofArray (s1 .toByteArray (false )).asReadOnly ();
228228 try {
229- final DoublesUnion u = DoublesUnion .writableWrap (seg , null );
229+ final DoublesUnion u = DoublesUnion .wrap (seg , null );
230230 } catch (final SketchesReadOnlyException e ) {
231231 //expected
232232 }
@@ -239,7 +239,7 @@ public void wrapUnionFromCompact() {
239239 s1 .update (1 );
240240 s1 .update (2 );
241241 final MemorySegment seg = MemorySegment .ofArray (s1 .toByteArray (true ));
242- DoublesUnion .writableWrap (seg , null ); //not from compact
242+ DoublesUnion .wrap (seg , null ); //not from compact
243243 fail ();
244244 }
245245
Original file line number Diff line number Diff line change @@ -685,7 +685,7 @@ public void checkWrapInstance() {
685685
686686 final byte [] byteArr = sketch .toByteArray (false );
687687 final MemorySegment seg = MemorySegment .ofArray (byteArr );
688- final DoublesUnion union = DoublesUnion .writableWrap (seg , null );
688+ final DoublesUnion union = DoublesUnion .wrap (seg , null );
689689 Assert .assertFalse (union .isEmpty ());
690690 assertTrue (union .hasMemorySegment ());
691691 assertFalse (union .isOffHeap ());
You can’t perform that action at this time.
0 commit comments