Skip to content

Commit 0795a6e

Browse files
committed
Improve & correct Javadocs
Add some missing methods.
1 parent 3e4eae0 commit 0795a6e

13 files changed

Lines changed: 39 additions & 22 deletions

.github/workflows/auto-jdk-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
jdk: [ 21 ]
23+
jdk: [ 24 ]
2424

2525
env:
2626
JDK_VERSION: ${{ matrix.jdk }}

.github/workflows/auto-os-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222

2323
matrix:
24-
jdk: [ 21 ]
24+
jdk: [ 24 ]
2525
os: [ windows-latest, ubuntu-latest, macos-latest ]
2626
include:
2727
- os: windows-latest

.github/workflows/check_cpp_files.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup Java
2828
uses: actions/setup-java@v4
2929
with:
30-
java-version: '21'
30+
java-version: '24'
3131
distribution: 'temurin'
3232

3333
- name: Configure C++ build

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
with:
3636
distribution: 'temurin'
3737
cache: 'maven'
38-
java-version: '21'
38+
java-version: '24'
3939

4040
- name: Initialize CodeQL
4141
uses: github/codeql-action/init@v3

.github/workflows/javadoc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup Java
1717
uses: actions/setup-java@v4
1818
with:
19-
java-version: '21'
19+
java-version: '24'
2020
distribution: 'temurin'
2121

2222
- name: Echo Java Version

src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.datasketches.quantiles;
2121

2222
import static org.apache.datasketches.common.Util.LS;
23+
import static org.apache.datasketches.quantiles.ClassicUtil.checkIsMemorySegmentCompact;
2324
import static org.apache.datasketches.quantiles.DoublesUtil.copyToHeap;
2425

2526
import java.lang.foreign.MemorySegment;
@@ -111,8 +112,8 @@ static DoublesUnionImpl heapifyInstance(final MemorySegment srcSeg) {
111112
}
112113

113114
/**
114-
* Returns an updatable Union object that wraps the data of the given MemorySegment
115-
* image of a updatable DoublesSketch. The data of the Union will remain in the MemorySegment.
115+
* Returns an Union object that wraps the data of the given MemorySegment image of a UpdateDoublesSketch.
116+
* The data of the Union will remain in the MemorySegment.
116117
*
117118
* @param srcSeg A MemorySegment image of an updatable DoublesSketch to be used as the data structure for the union and will be modified.
118119
* @param mSegReq the MemorySegmentRequest used if the given MemorySegment needs to expand.
@@ -138,7 +139,12 @@ public void union(final DoublesSketch sketchIn) {
138139
@Override
139140
public void union(final MemorySegment seg) {
140141
Objects.requireNonNull(seg);
141-
gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.writableWrap(seg, null));
142+
if (checkIsMemorySegmentCompact(seg)) {
143+
gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.wrap(seg));
144+
} else {
145+
gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.writableWrap(seg, null));
146+
}
147+
142148
gadget_.doublesSV = null;
143149
}
144150

src/test/java/org/apache/datasketches/quantiles/DirectCompactDoublesSketchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void wrapEmptyCompactSketch() {
9797
final CompactDoublesSketch s1 = DoublesSketch.builder().build().compact();
9898
final MemorySegment seg
9999
= MemorySegment.ofBuffer(ByteBuffer.wrap(s1.toByteArray()).order(ByteOrder.nativeOrder()));
100-
final DoublesSketch s2 = DoublesSketch.wrap(seg, MemorySegmentRequest.DEFAULT);
100+
final DoublesSketch s2 = DoublesSketch.wrap(seg);
101101
assertTrue(s2.isEmpty());
102102
assertEquals(s2.getN(), 0);
103103
assertTrue(Double.isNaN(s2.isEmpty() ? Double.NaN : s2.getMinItem()));

src/test/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void serializeDeserialize() {
230230

231231
final byte[] arr2 = sketch2.toByteArray(false);
232232
assertEquals(arr2.length, sketch2.getSerializedSizeBytes());
233-
final DoublesSketch sketch3 = DoublesSketch.wrap(MemorySegment.ofArray(arr2), null);
233+
final DoublesSketch sketch3 = DoublesSketch.writableWrap(MemorySegment.ofArray(arr2), null);
234234
assertEquals(sketch3.getMinItem(), 0.0);
235235
assertEquals(sketch3.getMaxItem(), 1999.0);
236236
assertEquals(sketch3.getQuantile(0.5), 1000.0, 10.0);

src/test/java/org/apache/datasketches/quantiles/DoublesMiscTest.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void heapToDirect() {
4343
for (int i = 0; i < 1000; i++) {
4444
heapSketch.update(i);
4545
}
46-
final DoublesSketch directSketch = DoublesSketch.wrap(MemorySegment.ofArray(heapSketch.toByteArray(false)), null);
46+
final DoublesSketch directSketch = DoublesSketch.writableWrap(MemorySegment.ofArray(heapSketch.toByteArray(false)), null);
4747

4848
assertEquals(directSketch.getMinItem(), 0.0);
4949
assertEquals(directSketch.getMaxItem(), 999.0);

0 commit comments

Comments
 (0)