You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2022/12/02 01:02:07 UTC
[datasketches-memory] branch IntegrateJava17_v2 updated: Interim changes 1
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch IntegrateJava17_v2
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
The following commit(s) were added to refs/heads/IntegrateJava17_v2 by this push:
new 1896abc Interim changes 1
1896abc is described below
commit 1896abcd8d9c103511e319782ed2042786af3549
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Thu Dec 1 17:02:00 2022 -0800
Interim changes 1
---
.../org/apache/datasketches/memory/BaseState.java | 42 +++--
.../memory/internal/BaseStateImpl.java | 10 +-
.../memory/internal/BaseWritableMemoryImpl.java | 6 +-
.../apache/datasketches/memory/internal/Util.java | 2 +-
.../datasketches/memory/internal/LeafImplTest.java | 2 +-
.../memory/internal/MemoryWriteToTest.java | 2 +-
.../memory/internal/WritableMemoryTest.java | 2 +-
.../org/apache/datasketches/memory/BaseState.java | 193 +++++++++++----------
.../memory/internal/BaseStateImpl.java | 16 +-
.../memory/internal/CompareAndCopy.java | 2 +-
.../apache/datasketches/memory/internal/Util.java | 4 -
.../memory/internal/BaseStateTest.java | 7 -
.../datasketches/memory/internal/LeafImplTest.java | 5 +-
.../memory/internal/MemoryWriteToTest.java | 14 +-
.../memory/internal/WritableMemoryTest.java | 16 +-
15 files changed, 154 insertions(+), 169 deletions(-)
diff --git a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/BaseState.java
index 21b4308..b9d85b9 100644
--- a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/BaseState.java
+++ b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/BaseState.java
@@ -33,10 +33,6 @@ import jdk.incubator.foreign.ResourceScope;
*/
public interface BaseState {
-// static final ByteOrder NATIVE_BYTE_ORDER = ByteOrder.nativeOrder();
-// static final ByteOrder NON_NATIVE_BYTE_ORDER =
-// (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
-
/**
* Currently used only for test, hold for possible future use
*/
@@ -70,7 +66,10 @@ public interface BaseState {
* @param that the given BaseState object
* @return true if the given object has equal contents to this object.
*/
- boolean equalTo(BaseState that);
+ default boolean equalTo(BaseState that) {
+ if (that == null || this.getCapacity() != that.getCapacity()) return false;
+ return equalTo(0, that, 0, that.getCapacity());
+ }
/**
* Returns true if the given object is an instance of this class and has equal contents to
@@ -83,8 +82,7 @@ public interface BaseState {
* @return true if the given object has equal contents to this object in the given range of
* bytes.
*/
- boolean equalTo(long thisOffsetBytes, BaseState that,
- long thatOffsetBytes, long lengthBytes);
+ boolean equalTo(long thisOffsetBytes, BaseState that, long thatOffsetBytes, long lengthBytes);
/**
* Forces any changes made to the contents of this mapped segment to be written to the storage device described
@@ -93,6 +91,13 @@ public interface BaseState {
*/
void force();
+ /**
+ * Gets the current Type ByteOrder.
+ * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
+ * @return the current Type ByteOrder.
+ */
+ ByteOrder getByteOrder();
+
/**
* Gets the capacity of this object in bytes
* @return the capacity of this object in bytes
@@ -105,13 +110,6 @@ public interface BaseState {
*/
MemoryRequestServer getMemoryRequestServer();
- /**
- * Gets the current Type ByteOrder.
- * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
- * @return the current Type ByteOrder.
- */
- ByteOrder getByteOrder();
-
/**
* Returns true if this Memory is backed by a ByteBuffer.
* @return true if this Memory is backed by a ByteBuffer.
@@ -204,6 +202,14 @@ public interface BaseState {
*/
void load();
+ /**
+ * See <a href="https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incubator.foreign/jdk/incubator/foreign/MemorySegment.html#mismatch(jdk.incubator.foreign.MemorySegment)>mismatch</a>
+ * @param that the other BaseState
+ * @return the relative offset, in bytes, of the first mismatch between this and the given other BaseState object,
+ * otherwise -1 if no mismatch
+ */
+ long mismatch(BaseState that);
+
/**
* Returns a positive number if <i>this</i> overlaps <i>that</i> and <i>this</i> base address is ≤ <i>that</i>
* base address.
@@ -215,14 +221,6 @@ public interface BaseState {
*/
long nativeOverlap(BaseState that);
- /**
- * See <a href="https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incubator.foreign/jdk/incubator/foreign/MemorySegment.html#mismatch(jdk.incubator.foreign.MemorySegment)>mismatch</a>
- * @param that the other BaseState
- * @return the relative offset, in bytes, of the first mismatch between this and the given other BaseState object,
- * otherwise -1 if no mismatch
- */
- long mismatch(BaseState that);
-
/**
* Returns the resource scope associated with this memory segment.
* @return the resource scope associated with this memory segment.
diff --git a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
index fc09f2c..6dd942f 100644
--- a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -283,17 +283,11 @@ abstract class BaseStateImpl implements BaseState {
}
}
- @Override
- public final boolean equalTo(final BaseState that) {
- Objects.requireNonNull(that);
- return equalTo(0, that, 0, that.getCapacity());
- }
-
@Override
public final boolean equalTo(final long thisOffsetBytes, final BaseState that,
final long thatOffsetBytes, final long lengthBytes) {
- Objects.requireNonNull(that);
- return CompareAndCopy.equals(seg, thisOffsetBytes, ((BaseStateImpl) that).seg, thatOffsetBytes, lengthBytes);
+ if (that == null) { return false; }
+ return CompareAndCopy.equals(seg, thisOffsetBytes, ((BaseStateImpl) that).seg, thatOffsetBytes, lengthBytes);
}
@Override
diff --git a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 895d951..586e3ac 100644
--- a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -279,11 +279,11 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
return MemoryAccess.getByteAtOffset(seg, offsetBytes);
}
- @Override
+ @Override //fundamental limitation of MemorySegment in Java17
public final void getByteArray(final long offsetBytes, final byte[] dstArray,
final int dstOffsetBytes, final int lengthBytes) {
checkBounds(dstOffsetBytes, lengthBytes, dstArray.length);
- final MemorySegment srcSlice = seg.asSlice(offsetBytes, lengthBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, lengthBytes); //view
final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetBytes, lengthBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -309,7 +309,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
final ByteArrayOutputStream out) throws IOException {
checkBounds(offsetBytes, lengthBytes, seg.byteSize());
final byte[] bArr = new byte[lengthBytes];
- getByteArray(offsetBytes,bArr, 0, lengthBytes); //fundamental limitation of MemorySegment
+ getByteArray(offsetBytes,bArr, 0, lengthBytes);
out.writeBytes(bArr);
}
diff --git a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/Util.java b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/Util.java
index 6d42e3f..f0d2b87 100644
--- a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/Util.java
+++ b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/Util.java
@@ -32,7 +32,7 @@ import java.util.Objects;
/**
* @author Lee Rhodes
*/
-@SuppressWarnings("javadoc")
+//@SuppressWarnings("javadoc")
final class Util {
/**
diff --git a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/LeafImplTest.java b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/LeafImplTest.java
index 4dffd0c..73d5540 100644
--- a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -52,7 +52,7 @@ public class LeafImplTest {
public void requestClose(WritableMemory memToClose, WritableMemory newMemory) { }
}
- public static ByteOrder otherByteOrder(final ByteOrder order) {
+ private static ByteOrder otherByteOrder(final ByteOrder order) {
return (order == ByteOrder.nativeOrder()) ? NNBO : ByteOrder.nativeOrder();
}
diff --git a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/MemoryWriteToTest.java b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
index f995154..e8c0eca 100644
--- a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
+++ b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
@@ -91,7 +91,7 @@ public class MemoryWriteToTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream(cap);
mem.writeToByteStream(0, cap, baos);
byte[] result = baos.toByteArray();
- assertTrue(mem.equalTo(0, Memory.wrap(result), 0, cap));
+ assertTrue(mem.equalTo(Memory.wrap(result)));
//OR
byte[] barr = new byte[cap];
mem.getByteArray(0, barr, 0, cap);
diff --git a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/WritableMemoryTest.java b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/WritableMemoryTest.java
index 27981ba..0c1f908 100644
--- a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/WritableMemoryTest.java
+++ b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/WritableMemoryTest.java
@@ -78,7 +78,7 @@ public class WritableMemoryTest {
//assertTrue(eq1);
WritableMemory wmem2 = WritableMemory.allocate(len + 1);
- assertFalse(wmem1.equals(wmem2));
+ assertFalse(wmem1.equalTo(wmem2));
WritableMemory reg1 = wmem1.writableRegion(0, wmem1.getCapacity());
assertTrue(wmem1.equalTo(0, reg1, 0, wmem1.getCapacity()));
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
index 17ec307..6dad6a4 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.internal.BaseStateImpl;
+// intentional blank
/**
* Keeps key configuration state for Memory and Buffer plus some common static variables
@@ -33,54 +34,81 @@ import org.apache.datasketches.memory.internal.BaseStateImpl;
public interface BaseState {
/**
- * The java line separator character as a String.
+ * Currently used only for test, hold for possible future use
*/
- static final String LS = System.getProperty("line.separator");
+ static final MemoryRequestServer defaultMemReqSvr = null; //new DefaultMemoryRequestServer();
/**
- * The placeholder for the default MemoryRequestServer, if set at all.
+ * Gets the current size of active direct memory allocated.
+ * @return the current size of active direct memory allocated.
+ * @deprecated no longer supported
*/
- static final MemoryRequestServer defaultMemReqSvr = null; //new DefaultMemoryRequestServer();
+ @Deprecated
+ static long getCurrentDirectMemoryAllocated() {
+ return BaseStateImpl.getCurrentDirectMemoryAllocated();
+ }
- //Byte Order Related
+ /**
+ * Gets the current number of active direct memory allocations.
+ * @return the current number of active direct memory allocations.
+ * @deprecated no longer supported
+ */
+ @Deprecated
+ static long getCurrentDirectMemoryAllocations() {
+ return BaseStateImpl.getCurrentDirectMemoryAllocations();
+ }
/**
- * Gets the current Type ByteOrder.
- * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
- * @return the current Type ByteOrder.
+ * Gets the current size of active direct memory map allocated.
+ * @return the current size of active direct memory map allocated.
+ * @deprecated no longer supported
*/
- ByteOrder getTypeByteOrder();
+ @Deprecated
+ static long getCurrentDirectMemoryMapAllocated() {
+ return BaseStateImpl.getCurrentDirectMemoryMapAllocated();
+ }
/**
- * Returns true if the Native ByteOrder is the same as the ByteOrder of the
- * current Buffer or Memory and the same ByteOrder as the given byteOrder.
- * @param byteOrder the given ByteOrder
- * @return true if the Native ByteOrder is the same as the ByteOrder of the
- * current Buffer or Memory and the same ByteOrder as the given byteOrder.
+ * Gets the current number of active direct memory map allocations.
+ * @return the current number of active direct memory map allocations.
+ * @deprecated no longer supported
*/
- boolean isByteOrderCompatible(ByteOrder byteOrder);
+ @Deprecated
+ static long getCurrentDirectMemoryMapAllocations() {
+ return BaseStateImpl.getCurrentDirectMemoryMapAllocations();
+ }
/**
- * Returns true if the given object is an instance of this class and has equal data contents.
- * @param that the given object
- * @return true if the given Object is an instance of this class and has equal data contents.
+ * Checks that the specified range of bytes is within bounds of this object, throws
+ * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes < 0, or length < 0,
+ * or offsetBytes + length > {@link #getCapacity()}.
+ * @param offsetBytes the given offset in bytes of this object
+ * @param lengthBytes the given length in bytes of this object
*/
- @Override
- boolean equals(Object that);
+ void checkValidAndBounds(long offsetBytes, long lengthBytes);
+
+ /**
+ * Returns true if the given object is an instance of this class and has equal contents to
+ * this object.
+ * @param that the given BaseState object
+ * @return true if the given object has equal contents to this object.
+ */
+ default boolean equalTo(BaseState that) {
+ if (that == null || this.getCapacity() != that.getCapacity()) return false;
+ return equalTo(0, that, 0, that.getCapacity());
+ }
/**
* Returns true if the given object is an instance of this class and has equal contents to
* this object in the given range of bytes. This will also check two distinct ranges within the
* same object for equals.
* @param thisOffsetBytes the starting offset in bytes for this object.
- * @param that the given object
- * @param thatOffsetBytes the starting offset in bytes for the given object
+ * @param that the given BaseState object
+ * @param thatOffsetBytes the starting offset in bytes for the given BaseState object
* @param lengthBytes the size of the range in bytes
- * @return true if the given object has equal contents to this object in the given range of
- * bytes.
+ * @return true if the given BaseState object has equal contents to this object in the given range of bytes.
*/
- boolean equalTo(long thisOffsetBytes, Object that,
- long thatOffsetBytes, long lengthBytes);
+ boolean equalTo(long thisOffsetBytes, BaseState that, long thatOffsetBytes, long lengthBytes);
/**
* Gets the backing ByteBuffer if it exists, otherwise returns null.
@@ -133,12 +161,25 @@ public interface BaseState {
*/
long getRegionOffset(long offsetBytes);
+ /**
+ * Gets the current Type ByteOrder.
+ * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
+ * @return the current Type ByteOrder.
+ */
+ ByteOrder getTypeByteOrder();
+
/**
* Returns true if this object is backed by an on-heap primitive array
* @return true if this object is backed by an on-heap primitive array
*/
boolean hasArray();
+ /**
+ * Returns true if this Memory is backed by a ByteBuffer.
+ * @return true if this Memory is backed by a ByteBuffer.
+ */
+ boolean hasByteBuffer();
+
/**
* Returns the hashCode of this object.
*
@@ -155,32 +196,13 @@ public interface BaseState {
int hashCode();
/**
- * Returns the 64-bit hash of the sequence of bytes in this object specified by
- * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>. Note that the sequence of bytes is
- * always processed in the same order independent of endianness.
- *
- * @param offsetBytes the given offset in bytes to the first byte of the byte sequence.
- * @param lengthBytes the given length in bytes of the byte sequence.
- * @param seed the given long seed.
- * @return the 64-bit hash of the sequence of bytes in this object specified by
- * <i>offsetBytes</i> and <i>lengthBytes</i>.
- */
- long xxHash64(long offsetBytes, long lengthBytes, long seed);
-
- /**
- * Returns a 64-bit hash from a single long. This method has been optimized for speed when only
- * a single hash of a long is required.
- * @param in A long.
- * @param seed A long valued seed.
- * @return the hash.
- */
- long xxHash64(long in, long seed);
-
- /**
- * Returns true if this Memory is backed by a ByteBuffer.
- * @return true if this Memory is backed by a ByteBuffer.
+ * Returns true if the Native ByteOrder is the same as the ByteOrder of the
+ * current Buffer or Memory and the same ByteOrder as the given byteOrder.
+ * @param byteOrder the given ByteOrder
+ * @return true if the Native ByteOrder is the same as the ByteOrder of the
+ * current Buffer or Memory and the same ByteOrder as the given byteOrder.
*/
- boolean hasByteBuffer();
+ boolean isByteOrderCompatible(ByteOrder byteOrder);
/**
* Returns true if the backing resource is direct (off-heap) memory.
@@ -195,6 +217,8 @@ public interface BaseState {
*/
boolean isReadOnly();
+ //Monitoring
+
/**
* Returns true if the backing resource of <i>this</i> is identical with the backing resource
* of <i>that</i>. The capacities must be the same. If <i>this</i> is a region,
@@ -213,58 +237,37 @@ public interface BaseState {
boolean isValid();
/**
- * Checks that the specified range of bytes is within bounds of this object, throws
- * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes < 0, or length < 0,
- * or offsetBytes + length > {@link #getCapacity()}.
- * @param offsetBytes the given offset in bytes of this object
- * @param lengthBytes the given length in bytes of this object
- */
- void checkValidAndBounds(long offsetBytes, long lengthBytes);
-
- //Monitoring
-
- /**
- * Gets the current number of active direct memory allocations.
- * @return the current number of active direct memory allocations.
- */
- static long getCurrentDirectMemoryAllocations() {
- return BaseStateImpl.getCurrentDirectMemoryAllocations();
- }
-
- /**
- * Gets the current size of active direct memory allocated.
- * @return the current size of active direct memory allocated.
- */
- static long getCurrentDirectMemoryAllocated() {
- return BaseStateImpl.getCurrentDirectMemoryAllocated();
- }
-
- /**
- * Gets the current number of active direct memory map allocations.
- * @return the current number of active direct memory map allocations.
+ * Returns a formatted hex string of a range of this object.
+ * Used primarily for testing.
+ * @param header a descriptive header
+ * @param offsetBytes offset bytes relative to this object start
+ * @param lengthBytes number of bytes to convert to a hex string
+ * @return a formatted hex string in a human readable array
*/
- static long getCurrentDirectMemoryMapAllocations() {
- return BaseStateImpl.getCurrentDirectMemoryMapAllocations();
- }
+ String toHexString(String header, long offsetBytes, int lengthBytes);
/**
- * Gets the current size of active direct memory map allocated.
- * @return the current size of active direct memory map allocated.
+ * Returns a 64-bit hash from a single long. This method has been optimized for speed when only
+ * a single hash of a long is required.
+ * @param in A long.
+ * @param seed A long valued seed.
+ * @return the hash.
*/
- static long getCurrentDirectMemoryMapAllocated() {
- return BaseStateImpl.getCurrentDirectMemoryMapAllocated();
- }
+ long xxHash64(long in, long seed);
//TO STRING
/**
- * Returns a formatted hex string of a range of this object.
- * Used primarily for testing.
- * @param header a descriptive header
- * @param offsetBytes offset bytes relative to this object start
- * @param lengthBytes number of bytes to convert to a hex string
- * @return a formatted hex string in a human readable array
+ * Returns the 64-bit hash of the sequence of bytes in this object specified by
+ * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>. Note that the sequence of bytes is
+ * always processed in the same order independent of endianness.
+ *
+ * @param offsetBytes the given offset in bytes to the first byte of the byte sequence.
+ * @param lengthBytes the given length in bytes of the byte sequence.
+ * @param seed the given long seed.
+ * @return the 64-bit hash of the sequence of bytes in this object specified by
+ * <i>offsetBytes</i> and <i>lengthBytes</i>.
*/
- String toHexString(String header, long offsetBytes, int lengthBytes);
+ long xxHash64(long offsetBytes, long lengthBytes, long seed);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 08a3175..2692725 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -22,6 +22,7 @@ package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.UnsafeUtil.assertBounds;
import static org.apache.datasketches.memory.internal.UnsafeUtil.checkBounds;
import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
+import static org.apache.datasketches.memory.internal.Util.LS;
import static org.apache.datasketches.memory.internal.Util.NATIVE_BYTE_ORDER;
import static org.apache.datasketches.memory.internal.Util.NON_NATIVE_BYTE_ORDER;
@@ -124,19 +125,10 @@ public abstract class BaseStateImpl implements BaseState {
}
@Override
- public final boolean equals(final Object that) {
- if (this == that) { return true; }
- return that instanceof BaseStateImpl
- ? CompareAndCopy.equals(this, (BaseStateImpl) that)
- : false;
- }
-
- @Override
- public final boolean equalTo(final long thisOffsetBytes, final Object that,
+ public final boolean equalTo(final long thisOffsetBytes, final BaseState that,
final long thatOffsetBytes, final long lengthBytes) {
- return that instanceof BaseStateImpl
- ? CompareAndCopy.equals(this, thisOffsetBytes, (BaseStateImpl) that, thatOffsetBytes, lengthBytes)
- : false;
+ if (that == null) { return false; }
+ return CompareAndCopy.equals(this, thisOffsetBytes, (BaseStateImpl) that, thatOffsetBytes, lengthBytes);
}
//Overridden by ByteBuffer Leafs
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
index cb5b9b0..225a18b 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
@@ -66,7 +66,7 @@ final class CompareAndCopy {
return (cap1 == cap2) && equals(state1, 0, state2, 0, cap1);
}
- //Developer notes: this is subtlely different from (campare == 0) in that this has an early
+ //Developer notes: this is subtly different from (compare == 0) in that this has an early
// stop if the arrays and offsets are the same as there is only one length. Also this can take
// advantage of chunking with longs, while compare cannot.
static boolean equals(
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
index aadb067..df4f18f 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -47,10 +47,6 @@ public final class Util {
public static final ByteOrder NON_NATIVE_BYTE_ORDER = NATIVE_BYTE_ORDER == ByteOrder.LITTLE_ENDIAN
? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
- public static ByteOrder otherByteOrder(final ByteOrder order) {
- return (order == NATIVE_BYTE_ORDER) ? NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
- }
-
/**
* Don't use sun.misc.Unsafe#copyMemory to copy blocks of memory larger than this
* threshold, because internally it doesn't have safepoint polls, that may cause long
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
index 20c96ca..dcc227a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
@@ -53,13 +53,6 @@ public class BaseStateTest {
assertTrue(wbuf.isSameResource(buf));
}
- @Test
- public void checkNotEqualTo() {
- byte[] arr = new byte[8];
- Memory mem = Memory.wrap(arr);
- assertFalse(mem.equalTo(0, arr, 0, 8));
- }
-
//StepBoolean checks
@Test
public void checkStepBoolean() {
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
index a6706c9..cb45b4b 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -21,7 +21,6 @@ package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.Util.NATIVE_BYTE_ORDER;
import static org.apache.datasketches.memory.internal.Util.NON_NATIVE_BYTE_ORDER;
-import static org.apache.datasketches.memory.internal.Util.otherByteOrder;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
@@ -48,6 +47,10 @@ public class LeafImplTest {
private static final ByteOrder NNBO = NON_NATIVE_BYTE_ORDER;
private static final MemoryRequestServer dummyMemReqSvr = new DummyMemoryRequestServer();
+ private static ByteOrder otherByteOrder(final ByteOrder order) {
+ return (order == ByteOrder.nativeOrder()) ? NNBO : ByteOrder.nativeOrder();
+ }
+
static class DummyMemoryRequestServer implements MemoryRequestServer {
@Override
public WritableMemory request(WritableMemory currentWMem, long capacityBytes) { return null; }
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
index 78e51ab..0d565a5 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryWriteToTest.java
@@ -20,6 +20,8 @@
package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.Util.UNSAFE_COPY_THRESHOLD_BYTES;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -27,10 +29,9 @@ import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.WritableMemory;
-import org.testng.Assert;
import org.testng.annotations.Test;
public class MemoryWriteToTest {
@@ -86,11 +87,16 @@ public class MemoryWriteToTest {
}
private static void testWriteTo(Memory mem) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ int cap = (int)mem.getCapacity();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(cap);
try (WritableByteChannel out = Channels.newChannel(baos)) {
mem.writeTo(0, mem.getCapacity(), out);
}
byte[] result = baos.toByteArray();
- Assert.assertTrue(mem.equals(Memory.wrap(result)));
+ assertTrue(mem.equalTo(Memory.wrap(result)));
+ //OR
+ byte[] barr = new byte[cap];
+ mem.getByteArray(0, barr, 0, cap);
+ assertEquals(barr, result);
}
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
index 2d11a44..89a36f3 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
@@ -88,17 +88,17 @@ public class WritableMemoryTest {
//assertTrue(eq1);
WritableMemory wmem2 = WritableMemory.allocate(len + 1);
- assertFalse(wmem1.equals(wmem2));
+ assertFalse(wmem1.equalTo(wmem2));
WritableMemory reg1 = wmem1.writableRegion(0, wmem1.getCapacity());
- assertTrue(wmem1.equals(reg1));
+ assertTrue(wmem1.equalTo(reg1));
wmem2 = WritableMemory.allocate(len);
for (int i = 0; i < len; i++) {
wmem1.putByte(i, (byte) i);
wmem2.putByte(i, (byte) i);
}
- assertTrue(wmem1.equals(wmem2));
+ assertTrue(wmem1.equalTo(wmem2));
assertTrue(wmem1.equalTo(0, wmem1, 0, len));
reg1 = wmem1.writableRegion(0, wmem1.getCapacity());
@@ -124,14 +124,14 @@ public class WritableMemoryTest {
public void checkEquals2() {
int len = 23;
WritableMemory wmem1 = WritableMemory.allocate(len);
- assertFalse(wmem1.equals(null));
+ assertFalse(wmem1.equalTo(null));
//@SuppressWarnings({"EqualsWithItself", "SelfEquals"}) //unsupported
//SelfEquals for Plexus, EqualsWithItself for IntelliJ
//boolean eq1 = wmem1.equals(wmem1); //strict profile complains
//assertTrue(eq1);
WritableMemory wmem2 = WritableMemory.allocate(len + 1);
- assertFalse(wmem1.equals(wmem2));
+ assertFalse(wmem1.equalTo(wmem2));
for (int i = 0; i < len; i++) {
wmem1.putByte(i, (byte) i);
@@ -151,14 +151,14 @@ public class WritableMemoryTest {
byte[] bytes2 = bytes1.clone();
Memory mem1 = Memory.wrap(bytes1);
Memory mem2 = Memory.wrap(bytes2);
- assertTrue(mem1.equals(mem2));
+ assertTrue(mem1.equalTo(mem2));
bytes2[thresh + 10] = (byte) (bytes1[thresh + 10] + 1);
- assertFalse(mem1.equals(mem2));
+ assertFalse(mem1.equalTo(mem2));
bytes2[thresh + 10] = bytes1[thresh + 10];
bytes2[(thresh * 2) + 3] = (byte) (bytes1[(thresh * 2) + 3] + 1);
- assertFalse(mem1.equals(mem2));
+ assertFalse(mem1.equalTo(mem2));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org