@@ -44,7 +44,7 @@ public void wrapAndUpdating() {
4444 Assert .assertEquals (bytes .length , curBytes );
4545 //convert to MemorySegment
4646 final MemorySegment seg = MemorySegment .ofArray (bytes );
47- final UpdateDoublesSketch sk2 = (UpdateDoublesSketch ) DoublesSketch .wrap (seg , null );
47+ final UpdateDoublesSketch sk2 = (UpdateDoublesSketch ) DoublesSketch .writableWrap (seg , null );
4848 assertEquals (seg .byteSize (), curBytes );
4949 sk2 .update (3 );
5050 sk2 .update (4 );
@@ -60,10 +60,8 @@ public void wrapCompactSketch() {
6060 final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
6161 s1 .update (1 );
6262 s1 .update (2 );
63- //MemorySegment seg = MemorySegment.ofArray(ByteBuffer.wrap(s1.compact().toByteArray())
64- // .asReadOnlyBuffer().order(ByteOrder.nativeOrder())););
6563 final MemorySegment seg = MemorySegment .ofArray (s1 .compact ().toByteArray ());
66- final DoublesSketch s2 = DoublesSketch .wrap (seg , null ); // compact, so this is ok
64+ final DoublesSketch s2 = DoublesSketch .wrap (seg ); // compact, so this is ok
6765 assertEquals (s2 .getMinItem (), 1.0 );
6866 assertEquals (s2 .getMaxItem (), 2.0 );
6967 assertEquals (s2 .getN (), 2 );
@@ -123,7 +121,7 @@ public void heapifyEmptyCompactSketch() {
123121 public void wrapEmptyUpdateSketch () {
124122 final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
125123 final MemorySegment seg = MemorySegment .ofArray (s1 .toByteArray ()).asReadOnly ();
126- final UpdateDoublesSketch s2 = (UpdateDoublesSketch ) DoublesSketch .wrap (seg , null );
124+ final UpdateDoublesSketch s2 = (UpdateDoublesSketch ) DoublesSketch .writableWrap (seg , null );
127125 assertTrue (s2 .isEmpty ());
128126
129127 // ensure the various put calls fail
@@ -189,7 +187,7 @@ public void wrapEmptyUpdateSketch() {
189187 public void wrapEmptyCompactSketch () {
190188 final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
191189 final MemorySegment seg = MemorySegment .ofArray (s1 .compact ().toByteArray ());
192- final DoublesSketch s2 = DoublesSketch .wrap (seg , null ); // compact, so this is ok
190+ final DoublesSketch s2 = DoublesSketch .wrap (seg ); // compact, so this is ok
193191 Assert .assertTrue (s2 .isEmpty ());
194192 }
195193
@@ -207,7 +205,7 @@ public void heapifyUnionFromSparse() {
207205 }
208206
209207 @ Test
210- public void heapifyUnionFromCompact () {
208+ public void initializeUnionFromCompactSegment () {
211209 final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
212210 s1 .update (1 );
213211 s1 .update (2 );
@@ -219,6 +217,19 @@ public void heapifyUnionFromCompact() {
219217 Assert .assertEquals (s2 .getMaxItem (), 3.0 );
220218 }
221219
220+ @ Test
221+ public void unionFromUpdatableSegment () {
222+ final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
223+ s1 .update (1 );
224+ s1 .update (2 );
225+ final MemorySegment seg = MemorySegment .ofArray (s1 .toByteArray (false ));
226+ final DoublesUnion u = DoublesUnion .wrap (seg );
227+ u .update (3 );
228+ final DoublesSketch s2 = u .getResult ();
229+ Assert .assertEquals (s2 .getMinItem (), 1.0 );
230+ Assert .assertEquals (s2 .getMaxItem (), 3.0 );
231+ }
232+
222233 @ Test
223234 public void wrapUnionFromHeap () {
224235 final UpdateDoublesSketch s1 = DoublesSketch .builder ().build ();
@@ -239,7 +250,7 @@ public void wrapUnionFromCompact() {
239250 s1 .update (1 );
240251 s1 .update (2 );
241252 final MemorySegment seg = MemorySegment .ofArray (s1 .toByteArray (true ));
242- DoublesUnion .wrap (seg , null ); //not from compact
253+ DoublesUnion .wrap (seg , null ); //compact seg
243254 fail ();
244255 }
245256
0 commit comments