2121
2222import static java .lang .Math .max ;
2323import static java .lang .Math .min ;
24- import static org .apache .datasketches .kll .KllPreambleUtil .getMemoryUpdatableFormatFlag ;
25- import static org .apache .datasketches .kll .KllSketch . Error . MUST_NOT_BE_UPDATABLE_FORMAT ;
24+ import static org .apache .datasketches .kll .KllPreambleUtil .SERIAL_VERSION_UPDATABLE ;
25+ import static org .apache .datasketches .kll .KllPreambleUtil . getMemorySerVer ;
2626import static org .apache .datasketches .kll .KllSketch .Error .TGT_IS_READ_ONLY ;
2727import static org .apache .datasketches .kll .KllSketch .Error .kllSketchThrow ;
2828import static org .apache .datasketches .kll .KllSketch .SketchType .DOUBLES_SKETCH ;
@@ -61,60 +61,56 @@ public abstract class KllDoublesSketch extends KllSketch implements QuantilesDou
6161 */
6262 public static KllDoublesSketch heapify (final Memory srcMem ) {
6363 Objects .requireNonNull (srcMem , "Parameter 'srcMem' must not be null" );
64- if (getMemoryUpdatableFormatFlag (srcMem )) { Error .kllSketchThrow (MUST_NOT_BE_UPDATABLE_FORMAT ); }
6564 return KllHeapDoublesSketch .heapifyImpl (srcMem );
6665 }
6766
6867 /**
69- * Create a new direct instance of this sketch with a given <em>k</em>.
70- * @param k parameter that controls size of the sketch and accuracy of estimates.
68+ * Create a new direct instance of this sketch with the default <em>k</em>.
69+ * The default <em>k</em> = 200 results in a normalized rank error of about
70+ * 1.65%. Larger <em>k</em> will have smaller error but the sketch will be larger (and slower).
7171 * @param dstMem the given destination WritableMemory object for use by the sketch
7272 * @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
7373 * @return a new direct instance of this sketch
7474 */
7575 public static KllDoublesSketch newDirectInstance (
76- final int k ,
7776 final WritableMemory dstMem ,
7877 final MemoryRequestServer memReqSvr ) {
79- Objects .requireNonNull (dstMem , "Parameter 'dstMem' must not be null" );
80- Objects .requireNonNull (memReqSvr , "Parameter 'memReqSvr' must not be null" );
81- return KllDirectDoublesSketch .newDirectInstance (k , DEFAULT_M , dstMem , memReqSvr );
78+ return newDirectInstance (DEFAULT_K , dstMem , memReqSvr );
8279 }
83-
80+
8481 /**
85- * Create a new direct instance of this sketch with the default <em>k</em>.
86- * The default <em>k</em> = 200 results in a normalized rank error of about
87- * 1.65%. Larger <em>k</em> will have smaller error but the sketch will be larger (and slower).
82+ * Create a new direct instance of this sketch with a given <em>k</em>.
83+ * @param k parameter that controls size of the sketch and accuracy of estimates.
8884 * @param dstMem the given destination WritableMemory object for use by the sketch
8985 * @param memReqSvr the given MemoryRequestServer to request a larger WritableMemory
9086 * @return a new direct instance of this sketch
9187 */
9288 public static KllDoublesSketch newDirectInstance (
89+ final int k ,
9390 final WritableMemory dstMem ,
9491 final MemoryRequestServer memReqSvr ) {
9592 Objects .requireNonNull (dstMem , "Parameter 'dstMem' must not be null" );
9693 Objects .requireNonNull (memReqSvr , "Parameter 'memReqSvr' must not be null" );
97- return KllDirectDoublesSketch .newDirectInstance (DEFAULT_K , DEFAULT_M , dstMem , memReqSvr );
94+ return KllDirectDoublesSketch .newDirectInstance (k , DEFAULT_M , dstMem , memReqSvr );
9895 }
9996
10097 /**
10198 * Create a new heap instance of this sketch with the default <em>k = 200</em>.
10299 * The default <em>k</em> = 200 results in a normalized rank error of about
103100 * 1.65%. Larger K will have smaller error but the sketch will be larger (and slower).
104- * This will have a rank error of about 1.65%.
105- * @return new KllDoublesSketch on the heap.
101+ * @return new KllDoublesSketch on the Java heap.
106102 */
107- public static KllDoublesSketch newHeapInstance () {
108- return new KllHeapDoublesSketch (DEFAULT_K , DEFAULT_M );
103+ public static KllDoublesSketch newHeapInstance () {
104+ return newHeapInstance (DEFAULT_K );
109105 }
110106
111107 /**
112108 * Create a new heap instance of this sketch with a given parameter <em>k</em>.
113- * <em>k</em> can be between DEFAULT_M and 65535, inclusive.
109+ * <em>k</em> can be between 8, inclusive, and 65535, inclusive.
114110 * The default <em>k</em> = 200 results in a normalized rank error of about
115111 * 1.65%. Larger K will have smaller error but the sketch will be larger (and slower).
116112 * @param k parameter that controls size of the sketch and accuracy of estimates.
117- * @return new KllDoublesSketch on the heap.
113+ * @return new KllDoublesSketch on the Java heap.
118114 */
119115 public static KllDoublesSketch newHeapInstance (final int k ) {
120116 return new KllHeapDoublesSketch (k , DEFAULT_M );
@@ -129,7 +125,7 @@ public static KllDoublesSketch newHeapInstance(final int k) {
129125 public static KllDoublesSketch wrap (final Memory srcMem ) {
130126 Objects .requireNonNull (srcMem , "Parameter 'srcMem' must not be null" );
131127 final KllMemoryValidate memVal = new KllMemoryValidate (srcMem , DOUBLES_SKETCH );
132- if (memVal . updatableMemFormat ) {
128+ if (getMemorySerVer ( srcMem ) == SERIAL_VERSION_UPDATABLE ) {
133129 return new KllDirectDoublesSketch ((WritableMemory ) srcMem , null , memVal );
134130 } else {
135131 return new KllDirectCompactDoublesSketch (srcMem , memVal );
@@ -148,10 +144,8 @@ public static KllDoublesSketch writableWrap(
148144 final MemoryRequestServer memReqSvr ) {
149145 Objects .requireNonNull (srcMem , "Parameter 'srcMem' must not be null" );
150146 final KllMemoryValidate memVal = new KllMemoryValidate (srcMem , DOUBLES_SKETCH );
151- if (memVal .updatableMemFormat ) {
152- if (!memVal .readOnly ) {
153- Objects .requireNonNull (memReqSvr , "Parameter 'memReqSvr' must not be null" );
154- }
147+ if (getMemorySerVer (srcMem ) == SERIAL_VERSION_UPDATABLE && !srcMem .isReadOnly ()) {
148+ Objects .requireNonNull (memReqSvr , "Parameter 'memReqSvr' must not be null" );
155149 return new KllDirectDoublesSketch (srcMem , memReqSvr , memVal );
156150 } else {
157151 return new KllDirectCompactDoublesSketch (srcMem , memVal );
0 commit comments