Skip to content

Commit daf0b14

Browse files
committed
Minor fixes for a SpotBugs issue
1 parent 9c80116 commit daf0b14

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

src/main/java/org/apache/datasketches/common/MemorySegmentStatus.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public interface MemorySegmentStatus {
4444
* Returns true if an internally referenced MemorySegment has the same backing resource as <i>that</i>,
4545
* or equivalently, if their two memory regions overlap. This applies to both on-heap and off-heap MemorySegments.
4646
*
47-
* <p>This returns false if either segment is <i>null</i> or not alive.</p>
48-
*
4947
* <p><b>Note:</b> If both segments are on-heap and not read-only, it can be determined if they were derived from
5048
* the same backing memory (array). However, this is not always possible off-heap. Because of this asymmetry, this definition
5149
* of "isSameResource" is confined to the existence of an overlap.</p>
@@ -59,8 +57,6 @@ public interface MemorySegmentStatus {
5957
* Returns true if the two given MemorySegments have to the same backing resource, or equivalently,
6058
* if the two memory regions overlap. This applies to both on-heap and off-heap MemorySegments.
6159
*
62-
* <p>This returns false if either segment is <i>null</i> or not alive.</p>
63-
*
6460
* <p><b>Note:</b> If both segments are on-heap and not read-only, it can be determined if they were derived from
6561
* the same backing memory (array). However, this is not always possible off-heap. Because of this asymmetry, this definition
6662
* of "isSameResource" is confined to the existence of an overlap.</p>
@@ -70,7 +66,6 @@ public interface MemorySegmentStatus {
7066
* @return true if the two given MemorySegments have to the same backing resource.
7167
*/
7268
static boolean isSameResource(final MemorySegment seg1, final MemorySegment seg2) {
73-
if ((seg1 == null) || (seg2 == null) || !seg1.scope().isAlive() || !seg2.scope().isAlive()) { return false; }
7469
final Optional<MemorySegment> opt = seg1.asOverlappingSlice(seg2);
7570
return opt.isPresent();
7671
}

src/test/java/org/apache/datasketches/hll/SizeAndModeTransitions.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,27 @@ public class SizeAndModeTransitions {
3333
static String[] hdr = {"Type", "Store", "LgK", "N", "Mode", "ActCBytes", "CmpBytes", "ActUBytes", "UpdBytes", "MaxBytes", "Estimate"};
3434

3535
@Test
36-
public void checkHLL8Heap() {
36+
public void checkHLL8with_withoutSeg() {
37+
checkHLL8Heap(true);
38+
checkHLL8Heap(false);
39+
}
40+
41+
private void checkHLL8Heap(final boolean withSeg) {
3742
final TgtHllType tgtHllType = TgtHllType.HLL_8;
38-
final boolean offHeap = false;
3943
final int lgK = 10;
4044
final int N = 97;
4145
printf(hfmt, (Object[]) hdr);
42-
final int maxBytes = HllSketch.getMaxUpdatableSerializationBytes(lgK, tgtHllType);
46+
4347
MemorySegment wseg = null;
4448
HllSketch sk;
45-
if (offHeap) {
49+
if (withSeg) {
50+
final int maxBytes = HllSketch.getMaxUpdatableSerializationBytes(lgK, tgtHllType);
4651
wseg = MemorySegment.ofArray(new byte[maxBytes]);
4752
sk = new HllSketch(lgK, tgtHllType, wseg);
4853
} else {
49-
sk = new HllSketch(lgK, tgtHllType);
54+
sk = new HllSketch(lgK, tgtHllType); //without segment
5055
}
51-
final String store = offHeap ? "MemorySegment" : "Heap";
56+
final String store = withSeg ? "MemorySegment" : "Heap";
5257
for (int i = 1; i <= N; i++) {
5358
sk.update(i);
5459
if (i == 7) { checkAtN(sk, tgtHllType, store, lgK, i, "LIST", 36, 40, 1064); }

src/test/java/org/apache/datasketches/theta/SketchTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ public void checkIsSameResource() {
343343
final DirectCompactSketch dcs = (DirectCompactSketch) sketch.compact(false, cseg);
344344
assertTrue(MemorySegmentStatus.isSameResource(dcs.getMemorySegment(), cseg));
345345
assertFalse(dcs.isOrdered());
346-
347-
final Sketch sk = Sketches.updateSketchBuilder().setNominalEntries(k).build();
348-
assertFalse(MemorySegmentStatus.isSameResource(sk.getMemorySegment(),seg));
349346
}
350347

351348
@Test

0 commit comments

Comments
 (0)