This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch thetaRework
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git


The following commit(s) were added to refs/heads/thetaRework by this push:
     new a3e416598 More cleanup.
a3e416598 is described below

commit a3e4165980743c86ddec562d0906bd0825321fe4
Author: Lee Rhodes <lee...@gmail.com>
AuthorDate: Thu Jun 26 13:20:55 2025 -0700

    More cleanup.
---
 .../theta2/DirectQuickSelectSketchR.java           |  3 +-
 .../apache/datasketches/theta2/Intersection.java   | 28 ++++++++++
 .../datasketches/theta2/IntersectionImpl.java      |  7 ++-
 .../apache/datasketches/theta2/SetOperation.java   | 11 ++--
 .../org/apache/datasketches/theta2/Sketches.java   | 46 ++++++++--------
 .../java/org/apache/datasketches/theta2/Union.java | 63 +++++++++++++++++++++-
 .../org/apache/datasketches/theta2/UnionImpl.java  |  2 +-
 .../arrayofdoubles/ArrayOfDoublesSketch.java       |  6 ++-
 .../arrayofdoubles/ArrayOfDoublesSketches.java     | 14 +++--
 .../tuple2/arrayofdoubles/ArrayOfDoublesUnion.java | 12 +++--
 .../ArrayOfDoublesUpdatableSketch.java             |  6 ++-
 .../apache/datasketches/theta2/UnionImplTest.java  |  4 +-
 12 files changed, 150 insertions(+), 52 deletions(-)

diff --git 
a/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketchR.java 
b/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketchR.java
index e2ba9f1fe..483cbbed6 100644
--- a/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketchR.java
+++ b/src/main/java/org/apache/datasketches/theta2/DirectQuickSelectSketchR.java
@@ -106,8 +106,7 @@ class DirectQuickSelectSketchR extends UpdateSketch {
     final int lgNomLongs = srcSeg.get(JAVA_BYTE, LG_NOM_LONGS_BYTE) & 0XFF;
     final int lgArrLongs = srcSeg.get(JAVA_BYTE, LG_ARR_LONGS_BYTE) & 0XFF;
 
-    final DirectQuickSelectSketchR dqss =
-        new DirectQuickSelectSketchR(seed, srcSeg);
+    final DirectQuickSelectSketchR dqss = new DirectQuickSelectSketchR(seed, 
srcSeg);
     dqss.hashTableThreshold_ = getOffHeapHashTableThreshold(lgNomLongs, 
lgArrLongs);
     return dqss;
   }
diff --git a/src/main/java/org/apache/datasketches/theta2/Intersection.java 
b/src/main/java/org/apache/datasketches/theta2/Intersection.java
index 143a5a1fb..30cb910d9 100644
--- a/src/main/java/org/apache/datasketches/theta2/Intersection.java
+++ b/src/main/java/org/apache/datasketches/theta2/Intersection.java
@@ -19,9 +19,11 @@
 
 package org.apache.datasketches.theta2;
 
+import static java.lang.foreign.ValueLayout.JAVA_BYTE;
 import static org.apache.datasketches.common.Util.floorPowerOf2;
 import static org.apache.datasketches.theta2.PreambleUtil.EMPTY_FLAG_MASK;
 import static org.apache.datasketches.theta2.PreambleUtil.SER_VER;
+import static org.apache.datasketches.theta2.PreambleUtil.SER_VER_BYTE;
 import static org.apache.datasketches.theta2.PreambleUtil.extractCurCount;
 import static org.apache.datasketches.theta2.PreambleUtil.extractFamilyID;
 import static org.apache.datasketches.theta2.PreambleUtil.extractFlags;
@@ -135,6 +137,32 @@ public abstract class Intersection extends SetOperation {
   public abstract CompactSketch intersect(Sketch a, Sketch b, boolean 
dstOrdered,
       MemorySegment dstSeg);
 
+  /**
+   * Factory: Wrap an Intersection target around the given source 
MemorySegment containing intersection data.
+   * This method assumes the <a 
href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update 
Seed</a>.
+   * If the given source MemorySegment is read-only, the returned object will 
also be read-only.
+   * @param srcSeg The source MemorySegment image.
+   * @return an Intersection that wraps a source MemorySegment that contains 
an Intersection image
+   */
+  public static Intersection wrap(final MemorySegment srcSeg) {
+    return wrap(srcSeg, ThetaUtil.DEFAULT_UPDATE_SEED);
+  }
+
+  /**
+   * Factory: Wrap an Intersection target around the given source 
MemorySegment containing intersection data.
+   * If the given source MemorySegment is read-only, the returned object will 
also be read-only.
+   * @param srcSeg The source MemorySegment image.
+   * @param expectedSeed <a 
href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
+   * @return an Intersection that wraps a source MemorySegment that contains 
an Intersection image
+   */
+  public static Intersection wrap(final MemorySegment srcSeg, final long 
expectedSeed) {
+    final int serVer = srcSeg.get(JAVA_BYTE, SER_VER_BYTE);
+    if (serVer != 3) {
+      throw new SketchesArgumentException("SerVer must be 3: " + serVer);
+    }
+    return IntersectionImpl.wrapInstance(srcSeg, expectedSeed, 
srcSeg.isReadOnly() );
+  }
+
   // Restricted
 
   /**
diff --git a/src/main/java/org/apache/datasketches/theta2/IntersectionImpl.java 
b/src/main/java/org/apache/datasketches/theta2/IntersectionImpl.java
index e16faa6e8..0d7a2bb8f 100644
--- a/src/main/java/org/apache/datasketches/theta2/IntersectionImpl.java
+++ b/src/main/java/org/apache/datasketches/theta2/IntersectionImpl.java
@@ -196,8 +196,8 @@ final class IntersectionImpl extends Intersection {
   }
 
   /**
-   * Factory: Wrap an Intersection target around the given source 
MemorySegment containing
-   * intersection data.
+   * Factory: Wrap an Intersection target around the given source 
MemorySegment containing intersection data.
+   * If the given source MemorySegment is read-only, the returned object will 
also be read-only.
    * @param srcSeg The source MemorySegment image.
    * @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See 
seed</a>
    * @param readOnly True if MemorySegment is to be treated as read only
@@ -218,8 +218,7 @@ final class IntersectionImpl extends Intersection {
   }
 
   @Override
-  public CompactSketch intersect(final Sketch a, final Sketch b, final boolean 
dstOrdered,
-     final MemorySegment dstSeg) {
+  public CompactSketch intersect(final Sketch a, final Sketch b, final boolean 
dstOrdered, final MemorySegment dstSeg) {
     if (wseg_ != null && readOnly_) { throw new SketchesReadOnlyException(); }
     hardReset();
     intersect(a);
diff --git a/src/main/java/org/apache/datasketches/theta2/SetOperation.java 
b/src/main/java/org/apache/datasketches/theta2/SetOperation.java
index 795712dca..227ae54db 100644
--- a/src/main/java/org/apache/datasketches/theta2/SetOperation.java
+++ b/src/main/java/org/apache/datasketches/theta2/SetOperation.java
@@ -104,11 +104,10 @@ public abstract class SetOperation implements 
MemorySegmentStatus {
   /**
    * Wrap takes the SetOperation image in MemorySegment and refers to it 
directly.
    * There is no data copying onto the java heap.
-   * This method assumes the
-   * <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default 
Update Seed</a>.
+   * This method assumes the <a 
href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update 
Seed</a>.
+   * If the given source MemorySegment is read-only, the returned object will 
also be read-only.
    *
-   * <p>Note: Only certain set operators during stateful operations can be 
serialized and thus
-   * wrapped.</p>
+   * <p>Note: Only certain set operators during stateful operations can be 
serialized and thus wrapped.</p>
    *
    * @param srcSeg an image of a SetOperation where the image seed hash 
matches the default seed hash.
    * @return a SetOperation backed by the given MemorySegment
@@ -120,9 +119,9 @@ public abstract class SetOperation implements 
MemorySegmentStatus {
   /**
    * Wrap takes the SetOperation image in MemorySegment and refers to it 
directly.
    * There is no data copying onto the java heap.
+   * If the given source MemorySegment is read-only, the returned object will 
also be read-only.
    *
-   * <p>Note: Only certain set operators during stateful operations can be 
serialized and thus
-   * wrapped.</p>
+   * <p>Note: Only certain set operators during stateful operations can be 
serialized and thus wrapped.</p>
    *
    * @param srcSeg an image of a SetOperation where the hash of the given 
expectedSeed matches the image seed hash.
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
diff --git a/src/main/java/org/apache/datasketches/theta2/Sketches.java 
b/src/main/java/org/apache/datasketches/theta2/Sketches.java
index 377345967..fa813b25f 100644
--- a/src/main/java/org/apache/datasketches/theta2/Sketches.java
+++ b/src/main/java/org/apache/datasketches/theta2/Sketches.java
@@ -71,7 +71,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#getMaxAnotBResultBytes(int)}.
+   * Convenience method, ref: {@link SetOperation#getMaxAnotBResultBytes(int)}.
    * Returns the maximum number of bytes for the returned CompactSketch, given 
the maximum
    * value of nomEntries of the first sketch A of AnotB.
    * @param maxNomEntries the given value
@@ -105,7 +105,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#getMaxIntersectionBytes(int)}
+   * Convenience method, ref: {@link SetOperation#getMaxIntersectionBytes(int)}
    * @param nomEntries Ref: {@link SetOperation#getMaxIntersectionBytes(int)}, 
{@code nomEntries}
    * @return Ref: {@link SetOperation#getMaxIntersectionBytes(int)}
    */
@@ -114,7 +114,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#getMaxUnionBytes(int)}
+   * Convenience method, ref: {@link SetOperation#getMaxUnionBytes(int)}
    * @param nomEntries Ref: {@link SetOperation#getMaxUnionBytes(int)}, {@code 
nomEntries}
    * @return Ref: {@link SetOperation#getMaxUnionBytes(int)}
    */
@@ -123,7 +123,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}
+   * Convenience method, ref: {@link Sketch#getMaxUpdateSketchBytes(int)}
    * @param nomEntries Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}, 
{@code nomEntries}
    * @return Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}
    */
@@ -132,7 +132,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#getSerializationVersion(MemorySegment)}
+   * Convenience method, ref: {@link 
Sketch#getSerializationVersion(MemorySegment)}
    * @param srcSeg Ref: {@link Sketch#getSerializationVersion(MemorySegment)}, 
{@code srcSeg}
    * @return Ref: {@link Sketch#getSerializationVersion(MemorySegment)}
    */
@@ -157,7 +157,7 @@ public final class Sketches {
   //Heapify Operations
 
   /**
-   * Ref: {@link CompactSketch#heapify(MemorySegment) 
CompactSketch.heapify(MemorySegment)}
+   * Convenience method, ref: {@link CompactSketch#heapify(MemorySegment) 
CompactSketch.heapify(MemorySegment)}
    * @param srcSeg Ref: {@link CompactSketch#heapify(MemorySegment) 
CompactSketch.heapify(MemorySegment)}, {@code srcSeg}
    * @return {@link CompactSketch CompactSketch}
    */
@@ -166,7 +166,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link CompactSketch#heapify(MemorySegment, long) 
CompactSketch.heapify(MemorySegment, long)}
+   * Convenience method, ref: {@link CompactSketch#heapify(MemorySegment, 
long) CompactSketch.heapify(MemorySegment, long)}
    * @param srcSeg Ref: {@link CompactSketch#heapify(MemorySegment, long) 
CompactSketch.heapify(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed Ref: {@link CompactSketch#heapify(MemorySegment, 
long) CompactSketch.heapify(MemorySegment, long)},
    * {@code expectedSeed}
@@ -177,7 +177,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link CompactSketch#wrap(MemorySegment) 
CompactSketch.wrap(MemorySegment)}
+   * Convenience method, ref: {@link CompactSketch#wrap(MemorySegment) 
CompactSketch.wrap(MemorySegment)}
    * @param srcSeg Ref: {@link CompactSketch#wrap(MemorySegment) 
CompactSketch.wrap(MemorySegment)}, {@code srcSeg}
    * @return {@link CompactSketch CompactSketch}
    */
@@ -186,7 +186,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link CompactSketch#wrap(MemorySegment, long) 
CompactSketch.wrap(MemorySegment, long)}
+   * Convenience method, ref: {@link CompactSketch#wrap(MemorySegment, long) 
CompactSketch.wrap(MemorySegment, long)}
    * @param srcSeg Ref: {@link CompactSketch#wrap(MemorySegment, long) 
CompactSketch.wrap(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed Ref: {@link CompactSketch#wrap(MemorySegment, long) 
CompactSketch.wrap(MemorySegment, long)},
    * {@code expectedSeed}
@@ -197,7 +197,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#heapify(MemorySegment) 
SetOperation.heapify(MemorySegment)}
+   * Convenience method, ref: {@link SetOperation#heapify(MemorySegment) 
SetOperation.heapify(MemorySegment)}
    * @param srcSeg Ref: {@link SetOperation#heapify(MemorySegment) 
SetOperation.heapify(MemorySegment)}, {@code srcSeg}
    * @return {@link SetOperation SetOperation}
    */
@@ -206,7 +206,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#heapify(MemorySegment, long) 
SetOperation.heapify(MemorySegment, long)}
+   * Convenience method, ref: {@link SetOperation#heapify(MemorySegment, long) 
SetOperation.heapify(MemorySegment, long)}
    * @param srcSeg Ref: {@link SetOperation#heapify(MemorySegment, long) 
SetOperation.heapify(MemorySegment, long)},
    * {@code srcSeg}
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
@@ -219,7 +219,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#heapify(MemorySegment) Sketch.heapify(MemorySegment)}
+   * Convenience method, ref: {@link Sketch#heapify(MemorySegment) 
Sketch.heapify(MemorySegment)}
    * @param srcSeg Ref: {@link Sketch#heapify(MemorySegment) 
Sketch.heapify(MemorySegment)}, {@code srcSeg}
    * @return {@link Sketch Sketch}
    */
@@ -228,7 +228,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#heapify(MemorySegment, long) 
Sketch.heapify(MemorySegment, long)}
+   * Convenience method, ref: {@link Sketch#heapify(MemorySegment, long) 
Sketch.heapify(MemorySegment, long)}
    * @param srcSeg Ref: {@link Sketch#heapify(MemorySegment, long) 
Sketch.heapify(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
    * Ref: {@link Sketch#heapify(MemorySegment, long) 
Sketch.heapify(MemorySegment, long)}, {@code expectedSeed}
@@ -239,7 +239,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link UpdateSketch#heapify(MemorySegment) 
UpdateSketch.heapify(MemorySegment)}
+   * Convenience method, ref: {@link UpdateSketch#heapify(MemorySegment) 
UpdateSketch.heapify(MemorySegment)}
    * @param srcSeg Ref: {@link UpdateSketch#heapify(MemorySegment) 
UpdateSketch.heapify(MemorySegment)}, {@code srcSeg}
    * @return {@link UpdateSketch UpdateSketch}
    */
@@ -248,7 +248,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link UpdateSketch#heapify(MemorySegment, long) 
UpdateSketch.heapify(MemorySegment, long)}
+   * Convenience method, ref: {@link UpdateSketch#heapify(MemorySegment, long) 
UpdateSketch.heapify(MemorySegment, long)}
    * @param srcSeg Ref: {@link UpdateSketch#heapify(MemorySegment, long) 
UpdateSketch.heapify(MemorySegment, long)},
    *   {@code srcSeg}
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
@@ -281,7 +281,7 @@ public final class Sketches {
   //Wrap operations
 
   /**
-   * Convenience method, calls {@link SetOperation#wrap(MemorySegment)} and 
casts the result to a Intersection
+   * Convenience method, ref: {@link SetOperation#wrap(MemorySegment)}
    * @param srcSeg Ref: {@link SetOperation#wrap(MemorySegment)}, {@code 
srcSeg}
    * @return a Intersection backed by the given MemorySegment
    */
@@ -290,7 +290,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#wrap(MemorySegment) 
SetOperation.wrap(MemorySegment)}
+   * Convenience method, ref: {@link SetOperation#wrap(MemorySegment) 
SetOperation.wrap(MemorySegment)}
    * @param srcSeg Ref: {@link SetOperation#wrap(MemorySegment) 
SetOperation.wrap(MemorySegment)}, {@code srcSeg}
    * @return {@link SetOperation SetOperation}
    */
@@ -299,7 +299,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link SetOperation#wrap(MemorySegment, long) 
SetOperation.wrap(MemorySegment, long)}
+   * Convenience method, ref: {@link SetOperation#wrap(MemorySegment, long) 
SetOperation.wrap(MemorySegment, long)}
    * @param srcSeg Ref: {@link SetOperation#wrap(MemorySegment, long) 
SetOperation.wrap(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
    * Ref: {@link SetOperation#wrap(MemorySegment, long) 
SetOperation.wrap(MemorySegment, long)}, {@code expectedSeed}
@@ -310,7 +310,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#wrap(MemorySegment) Sketch.wrap(MemorySegment)}
+   * Convenience method, ref: {@link Sketch#wrap(MemorySegment) 
Sketch.wrap(MemorySegment)}
    * @param srcSeg Ref: {@link Sketch#wrap(MemorySegment) 
Sketch.wrap(MemorySegment)}, {@code srcSeg}
    * @return {@link Sketch Sketch}
    */
@@ -319,7 +319,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link Sketch#wrap(MemorySegment, long) Sketch.wrap(MemorySegment, 
long)}
+   * Convenience method, ref: {@link Sketch#wrap(MemorySegment, long) 
Sketch.wrap(MemorySegment, long)}
    * @param srcSeg Ref: {@link Sketch#wrap(MemorySegment, long) 
Sketch.wrap(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed the expectedSeed used to validate the given 
MemorySegment image.
    * Ref: {@link Sketch#wrap(MemorySegment, long) Sketch.wrap(MemorySegment, 
long)}, {@code expectedSeed}
@@ -330,7 +330,7 @@ public final class Sketches {
   }
 
   /**
-   * Convenience method, calls {@link SetOperation#wrap(MemorySegment)} and 
casts the result to a Union
+   * Convenience method, ref: {@link SetOperation#wrap(MemorySegment)} and 
casts the result to a Union
    * @param srcSeg Ref: {@link SetOperation#wrap(MemorySegment)}, {@code 
srcSeg}
    * @return a Union backed by the given MemorySegment.
    */
@@ -339,7 +339,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link UpdateSketch#wrap(MemorySegment) 
UpdateSketch.wrap(MemorySegment)}
+   * Convenience method, ref: {@link UpdateSketch#wrap(MemorySegment) 
UpdateSketch.wrap(MemorySegment)}
    * @param srcSeg Ref: {@link UpdateSketch#wrap(MemorySegment) 
UpdateSketch.wrap(MemorySegment)}, {@code srcSeg}
    * @return {@link UpdateSketch UpdateSketch}
    */
@@ -348,7 +348,7 @@ public final class Sketches {
   }
 
   /**
-   * Ref: {@link UpdateSketch#wrap(MemorySegment, long) 
UpdateSketch.wrap(MemorySegment, long)}
+   * Convenience method, ref: {@link UpdateSketch#wrap(MemorySegment, long) 
UpdateSketch.wrap(MemorySegment, long)}
    * @param srcSeg Ref: {@link UpdateSketch#wrap(MemorySegment, long) 
UpdateSketch.wrap(MemorySegment, long)}, {@code srcSeg}
    * @param expectedSeed the seed used to validate the given MemorySegment 
image.
    * Ref: {@link UpdateSketch#wrap(MemorySegment, long) 
UpdateSketch.wrap(MemorySegment, long)}, {@code expectedSeed}
diff --git a/src/main/java/org/apache/datasketches/theta2/Union.java 
b/src/main/java/org/apache/datasketches/theta2/Union.java
index 861857366..fde9e90bd 100644
--- a/src/main/java/org/apache/datasketches/theta2/Union.java
+++ b/src/main/java/org/apache/datasketches/theta2/Union.java
@@ -19,10 +19,15 @@
 
 package org.apache.datasketches.theta2;
 
+import static java.lang.foreign.ValueLayout.JAVA_BYTE;
+import static org.apache.datasketches.theta2.PreambleUtil.SER_VER_BYTE;
+
 import java.lang.foreign.MemorySegment;
 import java.nio.ByteBuffer;
 
 import org.apache.datasketches.common.Family;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.thetacommon.ThetaUtil;
 
 /**
  * Compute the union of two or more theta sketches.
@@ -32,6 +37,62 @@ import org.apache.datasketches.common.Family;
  */
 public abstract class Union extends SetOperation {
 
+  /**
+   * Wrap a Union object around a Union MemorySegment object containing data.
+   * This method assumes the <a 
href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update 
Seed</a>.
+   * This does NO validity checking of the given MemorySegment.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
+   * @param srcSeg The source MemorySegment object.
+   * @return this class
+   */
+  public static Union fastWrap(final MemorySegment srcSeg) {
+    return fastWrap(srcSeg, ThetaUtil.DEFAULT_UPDATE_SEED);
+  }
+
+  /**
+   * Wrap a Union object around a Union MemorySegment object containing data.
+   * This does NO validity checking of the given MemorySegment.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
+   * @param srcSeg The source MemorySegment object.
+   * @param expectedSeed the seed used to validate the given MemorySegment 
image.
+   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
+   * @return this class
+   */
+  public static Union fastWrap(final MemorySegment srcSeg, final long 
expectedSeed) {
+    final int serVer = srcSeg.get(JAVA_BYTE, SER_VER_BYTE);
+    if (serVer != 3) {
+      throw new SketchesArgumentException("SerVer must be 3: " + serVer);
+    }
+    return UnionImpl.fastWrapInstance(srcSeg, expectedSeed);
+  }
+
+  /**
+   * Wrap a Union object around a Union MemorySegment object containing data.
+   * This method assumes the <a 
href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update 
Seed</a>.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
+   * @param srcSeg The source MemorySegment object.
+   * @return this class
+   */
+  public static Union wrap(final MemorySegment srcSeg) {
+    return wrap(srcSeg, ThetaUtil.DEFAULT_UPDATE_SEED);
+  }
+
+  /**
+   * Wrap a Union object around a Union MemorySegment object containing data.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
+   * @param srcSeg The source MemorySegment object.
+   * @param expectedSeed the seed used to validate the given MemorySegment 
image.
+   * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
+   * @return this class
+   */
+  public static Union wrap(final MemorySegment srcSeg, final long 
expectedSeed) {
+    final int serVer = srcSeg.get(JAVA_BYTE, SER_VER_BYTE);
+    if (serVer != 3) {
+      throw new SketchesArgumentException("SerVer must be 3: " + serVer);
+    }
+    return UnionImpl.wrapInstance(srcSeg, expectedSeed);
+  }
+
   /**
    * Returns the number of storage bytes required for this union in its 
current state.
    *
@@ -67,7 +128,7 @@ public abstract class Union extends SetOperation {
    * <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination 
Ordered</a>
    *
    * @param dstSeg destination MemorySegment
-   * 
+   *
    * @return the result of this operation as a CompactSketch of the chosen form
    */
   public abstract CompactSketch getResult(boolean dstOrdered, MemorySegment 
dstSeg);
diff --git a/src/main/java/org/apache/datasketches/theta2/UnionImpl.java 
b/src/main/java/org/apache/datasketches/theta2/UnionImpl.java
index 68d72b6e9..9d3aca04b 100644
--- a/src/main/java/org/apache/datasketches/theta2/UnionImpl.java
+++ b/src/main/java/org/apache/datasketches/theta2/UnionImpl.java
@@ -138,7 +138,7 @@ final class UnionImpl extends Union {
    * <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
    * @return this class
    */
-  static UnionImpl fastWrap(final MemorySegment srcSeg, final long 
expectedSeed) {
+  static UnionImpl fastWrapInstance(final MemorySegment srcSeg, final long 
expectedSeed) {
     Family.UNION.checkFamilyID(extractFamilyID(srcSeg));
     final UpdateSketch gadget = srcSeg.isReadOnly()
         ? DirectQuickSelectSketchR.fastReadOnlyWrap(srcSeg, expectedSeed)
diff --git 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketch.java
 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketch.java
index 49bf36cbb..99a87bbb1 100644
--- 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketch.java
+++ 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketch.java
@@ -94,7 +94,8 @@ public abstract class ArrayOfDoublesSketch {
   }
 
   /**
-   * Wrap the given MemorySegment as an ArrayOfDoublesSketch
+   * Wrap the given MemorySegment as an ArrayOfDoublesSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param seg the given MemorySegment
    * @return an ArrayOfDoublesSketch
    */
@@ -103,7 +104,8 @@ public abstract class ArrayOfDoublesSketch {
   }
 
   /**
-   * Wrap the given MemorySegment and seed as a ArrayOfDoublesSketch
+   * Wrap the given MemorySegment and seed as a ArrayOfDoublesSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param seg the given MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesSketch
diff --git 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketches.java
 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketches.java
index a439d4899..8ad121a00 100644
--- 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketches.java
+++ 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesSketches.java
@@ -67,7 +67,8 @@ public final class ArrayOfDoublesSketches {
   }
 
   /**
-   * Wrap the given MemorySegment as an ArrayOfDoublesSketch
+   * Wrap the given MemorySegment as an ArrayOfDoublesSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @return an ArrayOfDoublesSketch
    */
@@ -76,7 +77,8 @@ public final class ArrayOfDoublesSketches {
   }
 
   /**
-   * Wrap the given MemorySegment and seed as a ArrayOfDoublesSketch
+   * Wrap the given MemorySegment and seed as a ArrayOfDoublesSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesSketch
@@ -86,7 +88,8 @@ public final class ArrayOfDoublesSketches {
   }
 
   /**
-   * Wrap the given MemorySegment as an ArrayOfDoublesUpdatableSketch
+   * Wrap the given MemorySegment as an ArrayOfDoublesUpdatableSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @return an ArrayOfDoublesUpdatableSketch
    */
@@ -95,7 +98,8 @@ public final class ArrayOfDoublesSketches {
   }
 
   /**
-   * Wrap the given MemorySegment and seed as a ArrayOfDoublesUpdatableSketch
+   * Wrap the given MemorySegment and seed as a ArrayOfDoublesUpdatableSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesUpdatableSketch
@@ -125,6 +129,7 @@ public final class ArrayOfDoublesSketches {
 
   /**
    * Wrap the given MemorySegment as an ArrayOfDoublesUnion
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @return an ArrayOfDoublesUnion
    */
@@ -134,6 +139,7 @@ public final class ArrayOfDoublesSketches {
 
   /**
    * Wrap the given MemorySegment and seed as an ArrayOfDoublesUnion
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesUnion
diff --git 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUnion.java
 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUnion.java
index d00d21f86..1c57b881e 100644
--- 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUnion.java
+++ 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUnion.java
@@ -61,7 +61,7 @@ public abstract class ArrayOfDoublesUnion {
   }
 
   /**
-   * Heapify the given MemorySegment as an ArrayOfDoublesUnion
+   * Heapify the given MemorySegment as an ArrayOfDoublesUnion.
    * @param srcSeg the given source MemorySegment
    * @return an ArrayOfDoublesUnion
    */
@@ -70,7 +70,7 @@ public abstract class ArrayOfDoublesUnion {
   }
 
   /**
-   * Heapify the given MemorySegment and seed as an ArrayOfDoublesUnion
+   * Heapify the given MemorySegment and seed as an ArrayOfDoublesUnion.
    * @param srcSeg the given source MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesUnion
@@ -80,7 +80,8 @@ public abstract class ArrayOfDoublesUnion {
   }
 
   /**
-   * Wrap the given MemorySegment as an ArrayOfDoublesUnion
+   * Wrap the given MemorySegment as an ArrayOfDoublesUnion.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @return an ArrayOfDoublesUnion
    */
@@ -89,7 +90,8 @@ public abstract class ArrayOfDoublesUnion {
   }
 
   /**
-   * Wrap the given MemorySegment and seed as an ArrayOfDoublesUnion
+   * Wrap the given MemorySegment and seed as an ArrayOfDoublesUnion.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param srcSeg the given source MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesUnion
@@ -104,7 +106,7 @@ public abstract class ArrayOfDoublesUnion {
    *
    * <p>Nulls and empty sketches are ignored.</p>
    *
-   * @param tupleSketch sketch to add to the union
+   * @param tupleSketch sketch to add to the union.
    */
   public void union(final ArrayOfDoublesSketch tupleSketch) {
     if (tupleSketch == null) { return; }
diff --git 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUpdatableSketch.java
 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUpdatableSketch.java
index 1ebece067..98cf6699a 100644
--- 
a/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUpdatableSketch.java
+++ 
b/src/main/java/org/apache/datasketches/tuple2/arrayofdoubles/ArrayOfDoublesUpdatableSketch.java
@@ -61,7 +61,8 @@ public abstract class ArrayOfDoublesUpdatableSketch extends 
ArrayOfDoublesSketch
   }
 
   /**
-   * Wrap the given MemorySegment as an ArrayOfDoublesUpdatableSketch
+   * Wrap the given MemorySegment as an ArrayOfDoublesUpdatableSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param seg the given MemorySegment
    * @return an ArrayOfDoublesUpdatableSketch
    */
@@ -70,7 +71,8 @@ public abstract class ArrayOfDoublesUpdatableSketch extends 
ArrayOfDoublesSketch
   }
 
   /**
-   * Wrap the given MemorySegment and seed as a ArrayOfDoublesUpdatableSketch
+   * Wrap the given MemorySegment and seed as a ArrayOfDoublesUpdatableSketch.
+   * If the given source MemorySegment is read-only, the returned Union object 
will also be read-only.
    * @param seg the given MemorySegment
    * @param seed the given seed
    * @return an ArrayOfDoublesUpdatableSketch
diff --git a/src/test/java/org/apache/datasketches/theta2/UnionImplTest.java 
b/src/test/java/org/apache/datasketches/theta2/UnionImplTest.java
index bcd066146..f3a36de5d 100644
--- a/src/test/java/org/apache/datasketches/theta2/UnionImplTest.java
+++ b/src/test/java/org/apache/datasketches/theta2/UnionImplTest.java
@@ -128,10 +128,10 @@ public class UnionImplTest {
     final Union union = 
Sketches.setOperationBuilder().setNominalEntries(k).buildUnion(srcSeg);
     for (int i = 0; i < k; i++) { union.update(i); } //exact
     assertEquals(union.getResult().getEstimate(), k, 0.0);
-    final Union union2 = UnionImpl.fastWrap(srcSeg, seed);
+    final Union union2 = UnionImpl.fastWrapInstance(srcSeg, seed);
     assertEquals(union2.getResult().getEstimate(), k, 0.0);
     final MemorySegment srcSegR = srcSeg;
-    final Union union3 = UnionImpl.fastWrap(srcSegR, seed);
+    final Union union3 = UnionImpl.fastWrapInstance(srcSegR, seed);
     assertEquals(union3.getResult().getEstimate(), k, 0.0);
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@datasketches.apache.org
For additional commands, e-mail: commits-h...@datasketches.apache.org

Reply via email to