@@ -151,29 +151,59 @@ public static DoublesSketch heapify(final MemorySegment srcSeg) {
151151 }
152152
153153 /**
154- * Wrap this sketch around the given updatable MemorySegment image of a DoublesSketch, compact or updatable .
154+ * Wrap this sketch around the given MemorySegment image of a compact, read-only DoublesSketch .
155155 *
156- * @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 .
156+ * @param srcSeg the given MemorySegment image of a compact, read-only DoublesSketch.
157+ * @return a compact, read-only sketch that wraps the given MemorySegment .
158158 */
159159 public static DoublesSketch wrap (final MemorySegment srcSeg ) {
160+ if (!checkIsMemorySegmentCompact (srcSeg )) {
161+ throw new SketchesArgumentException ("MemorySegment sketch image must be in compact form." );
162+ }
163+ return DirectCompactDoublesSketch .wrapInstance (srcSeg );
164+ }
165+
166+ /**
167+ * Wrap this sketch around the given MemorySegment image of an updatable DoublesSketch.
168+ *
169+ * <p>The given MemorySegment must be writable and it must contain a <i>UpdateDoublesSketch</i>.
170+ * The sketch will be updated and managed totally within the MemorySegment. If the given source
171+ * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.</p>
172+ *
173+ * <p><b>NOTE:</b>If during updating of the sketch the sketch requires more capacity than the given size of the MemorySegment, the sketch
174+ * will request more capacity using the {@link MemorySegmentRequest MemorySegmentRequest} interface. The default of this interface will
175+ * return a new MemorySegment on the heap.</p>
176+ *
177+ * @param srcSeg the given MemorySegment image of an <i>UpdateDoublesSketch</i>.
178+ * @return an updatable sketch that wraps the given MemorySegment.
179+ */
180+ public static DoublesSketch writableWrap (final MemorySegment srcSeg ) {
160181 if (checkIsMemorySegmentCompact (srcSeg )) {
161- return DirectCompactDoublesSketch . wrapInstance ( srcSeg );
182+ throw new SketchesArgumentException ( "MemorySegment sketch image must be in updatable form." );
162183 }
163184 return DirectUpdateDoublesSketch .wrapInstance (srcSeg , null );
164185 }
165186
166187 /**
167- * Wrap this sketch around the given updatable MemorySegment image of a DoublesSketch, compact or updatable.
188+ * Wrap this sketch around the given MemorySegment image of an updatable DoublesSketch.
189+ *
190+ * <p>The given MemorySegment must be writable and it must contain a <i>UpdateDoublesSketch</i>.
191+ * The sketch will be updated and managed totally within the MemorySegment. If the given source
192+ * MemorySegment is created off-heap, then all the management of the sketch's internal data will be off-heap as well.</p>
193+ *
194+ * <p><b>NOTE:</b>If during updating of the sketch the sketch requires more capacity than the given size of the MemorySegment, the sketch
195+ * will request more capacity using the {@link MemorySegmentRequest MemorySegmentRequest} interface. The default of this interface will
196+ * return a new MemorySegment on the heap. It is up to the user to optionally extend this interface if more flexible
197+ * handling of requests for more capacity is required.</p>
168198 *
169- * @param srcSeg the given MemorySegment image of a DoublesSketch that may have data .
199+ * @param srcSeg the given MemorySegment image of a DoublesSketch.
170200 * @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand.
171201 * Otherwise, it can be null and the default MemorySegmentRequest will be used.
172- * @return a sketch that wraps the given srcSeg in read-only mode .
202+ * @return a sketch that wraps the given MemorySegment .
173203 */
174- public static DoublesSketch wrap (final MemorySegment srcSeg , final MemorySegmentRequest mSegReq ) {
204+ public static DoublesSketch writableWrap (final MemorySegment srcSeg , final MemorySegmentRequest mSegReq ) {
175205 if (checkIsMemorySegmentCompact (srcSeg )) {
176- return DirectCompactDoublesSketch . wrapInstance ( srcSeg );
206+ throw new SketchesArgumentException ( "MemorySegment sketch image must be in updatable form." );
177207 }
178208 return DirectUpdateDoublesSketch .wrapInstance (srcSeg , mSegReq );
179209 }
0 commit comments