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/06/01 21:07:12 UTC
[datasketches-memory17] branch main updated: Adding tests, cleanup.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-memory17.git
The following commit(s) were added to refs/heads/main by this push:
new af771d4 Adding tests, cleanup.
af771d4 is described below
commit af771d4b06614a8473e7a352f9312f239add219b
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Wed Jun 1 14:07:08 2022 -0700
Adding tests, cleanup.
---
src/main/java/module-info.java | 2 +-
.../org/apache/datasketches/memory/Memory.java | 13 +++---
.../apache/datasketches/memory/MurmurHash3.java | 2 +-
.../apache/datasketches/memory/WritableBuffer.java | 1 +
.../apache/datasketches/memory/WritableMemory.java | 8 ++--
.../memory/internal/BaseStateImpl.java | 42 +++++++------------
.../memory/internal/BaseWritableBufferImpl.java | 29 ++++---------
.../memory/internal/BaseWritableMemoryImpl.java | 28 ++++++-------
.../memory/internal/CompareAndCopy.java | 6 +--
.../memory/internal/MurmurHash3v3.java | 8 +++-
.../memory/internal/NativeWritableBufferImpl.java | 48 +++++++++++-----------
.../memory/internal/NativeWritableMemoryImpl.java | 48 +++++++++++-----------
.../internal/NonNativeWritableBufferImpl.java | 48 +++++++++++-----------
.../internal/NonNativeWritableMemoryImpl.java | 48 +++++++++++-----------
.../apache/datasketches/memory/internal/Util.java | 8 ++--
.../datasketches/memory/internal/XxHash64.java | 21 ++++++----
.../memory/internal/BaseStateTest.java | 7 +++-
.../datasketches/memory/internal/MemoryTest.java | 30 ++++++++++++++
.../memory/internal/SpecificLeafTest.java | 9 ++++
tools/MemoryCheckstyle.xml | 10 ++++-
20 files changed, 226 insertions(+), 190 deletions(-)
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index f5baf11..cdafde4 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-@SuppressWarnings("javadoc")
+//@SuppressWarnings("javadoc")
module org.apache.datasketches.memory {
requires java.base;
requires java.logging;
diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java b/src/main/java/org/apache/datasketches/memory/Memory.java
index 2c4586d..c7e0e79 100644
--- a/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -74,11 +74,12 @@ public interface Memory extends BaseState {
/**
* Maps the given file into <i>Memory</i> for read operations
* Calling this method is equivalent to calling
- * {@link #map(File, long, long, ResourceScope, ByteOrder) map(file, 0, file.length(), scope, ByteOrder.nativeOrder())}.
+ * {@link #map(File, long, long, ResourceScope, ByteOrder)
+ * map(file, 0, file.length(), scope, ByteOrder.nativeOrder())}.
* @param file the given file to map. It must be non-null with a non-negative length and readable.
* @param scope the given ResourceScope. It must be non-null.
* @return mapped Memory.
- * @throws Exception
+ * @throws Exception various IO exceptions
*/
static Memory map(File file, ResourceScope scope) throws Exception {
return map(file, 0, file.length(), scope, ByteOrder.nativeOrder());
@@ -92,7 +93,8 @@ public interface Memory extends BaseState {
* @param scope the given ResourceScope. It must be non-null.
* @param byteOrder the byte order to be used. It must be non-null.
* @return mapped Memory
- * @throws Exception
+ * @throws Exception various IO exceptions
+ * @throws IllegalArgumentException if file is not readable
*/
@SuppressWarnings("resource")
static Memory map(File file, long fileOffsetBytes, long capacityBytes, ResourceScope scope, ByteOrder byteOrder)
@@ -194,7 +196,7 @@ public interface Memory extends BaseState {
}
/**
- * Wraps the given primitive array for read operations assuming native byte order.
+ * Wraps the given primitive array for read operations with the given byte order.
* @param array the given primitive array. It must be non-null.
* @param offsetBytes the byte offset into the given array
* @param lengthBytes the number of bytes to include from the given array.
@@ -204,7 +206,7 @@ public interface Memory extends BaseState {
static Memory wrap(byte[] array, int offsetBytes, int lengthBytes, ByteOrder byteOrder) {
Objects.requireNonNull(array, "array must be non-null");
final MemorySegment slice = MemorySegment.ofArray(array).asSlice(offsetBytes, lengthBytes).asReadOnly();
- return BaseWritableMemoryImpl.wrapSegmentAsArray(slice, ByteOrder.nativeOrder(), null);
+ return BaseWritableMemoryImpl.wrapSegmentAsArray(slice, byteOrder, null);
}
/**
@@ -431,5 +433,4 @@ public interface Memory extends BaseState {
void writeToByteStream(long offsetBytes, int lengthBytes, ByteArrayOutputStream out)
throws IOException;
-
}
diff --git a/src/main/java/org/apache/datasketches/memory/MurmurHash3.java b/src/main/java/org/apache/datasketches/memory/MurmurHash3.java
index 69fd6a5..7fd992c 100644
--- a/src/main/java/org/apache/datasketches/memory/MurmurHash3.java
+++ b/src/main/java/org/apache/datasketches/memory/MurmurHash3.java
@@ -39,7 +39,7 @@ import jdk.incubator.foreign.MemorySegment;
* <p>This implementation produces exactly the same hash result as the
* MurmurHash3 function in datasketches-java given compatible inputs.</p>
*
- * * <p>This version 3 of the implementation leverages the jdk.incubator.foreign package of JDK-17 in place of
+ * <p>This version 3 of the implementation leverages the jdk.incubator.foreign package of JDK-17 in place of
* the Unsafe class.
*
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/WritableBuffer.java b/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
index 1d2ca70..d74af80 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
@@ -60,6 +60,7 @@ public interface WritableBuffer extends Buffer {
* @param byteBuffer the given ByteBuffer. It must be non-null and writable.
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>WritableBuffer</i> for write operations on the given <i>ByteBuffer</i>.
+ * @throws ReadOnlyException if ByteBuffer is not writable
*/
static WritableBuffer writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
Objects.requireNonNull(byteBuffer, "ByteBuffer must not be null");
diff --git a/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index 3d4f007..0027ff9 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -59,12 +59,13 @@ public interface WritableMemory extends Memory {
* @param byteBuffer the given <i>ByteBuffer</i>. It must be non-null and writable.
* @param byteOrder the byte order to be used. It must be non-null.
* @return a new <i>WritableMemory</i> for write operations on the given <i>ByteBuffer</i>.
+ * @throws ReadOnlyException if ByteBuffer is not writable.
*/
static WritableMemory writableWrap(ByteBuffer byteBuffer, ByteOrder byteOrder) {
Objects.requireNonNull(byteBuffer, "ByteBuffer must not be null");
Objects.requireNonNull(byteOrder, "ByteOrder must not be null");
if (byteBuffer.isReadOnly()) { throw new ReadOnlyException("ByteBuffer must be writable."); }
- ByteBuffer byteBuf = byteBuffer.position(0).limit(byteBuffer.capacity());
+ final ByteBuffer byteBuf = byteBuffer.position(0).limit(byteBuffer.capacity());
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteOrder);
}
@@ -79,7 +80,7 @@ public interface WritableMemory extends Memory {
* @param file the given file to map. It must be non-null with a non-negative length and writable.
* @param scope the give Resource Scope. It must be non-null.
* @return mapped WritableMemory
- * @throws Exception
+ * @throws Exception various IO exceptions
*/
static WritableMemory writableMap(File file, ResourceScope scope) throws Exception {
return writableMap(file, 0, file.length(), scope, ByteOrder.nativeOrder());
@@ -93,7 +94,8 @@ public interface WritableMemory extends Memory {
* @param scope the give Resource Scope. It must be non-null.
* @param byteOrder the byte order to be used. It must be non-null.
* @return mapped WritableMemory.
- * @throws Exception
+ * @throws Exception various IO exceptions
+ * @throws ReadOnlyException if file is not writable
*/
@SuppressWarnings("resource")
static WritableMemory writableMap(File file, long fileOffsetBytes, long capacityBytes, ResourceScope scope,
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index f7b8cb6..46f5a70 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -109,21 +109,6 @@ public abstract class BaseStateImpl implements BaseState {
@Override
public boolean isAlive() { return seg.scope().isAlive(); }
- /**
- * Assert the requested offset and length against the allocated size.
- * The invariants equation is: {@code 0 <= reqOff <= reqLen <= reqOff + reqLen <= allocSize}.
- * If this equation is violated and assertions are enabled, an {@link AssertionError} will
- * be thrown.
- * @param reqOff the requested offset
- * @param reqLen the requested length
- * @param allocSize the allocated size.
- */
- public static void assertBounds(final long reqOff, final long reqLen, final long allocSize) {
- assert ((reqOff | reqLen | (reqOff + reqLen) | (allocSize - (reqOff + reqLen))) >= 0) :
- "reqOffset: " + reqOff + ", reqLength: " + reqLen
- + ", (reqOff + reqLen): " + (reqOff + reqLen) + ", allocSize: " + allocSize;
- }
-
/**
* Check the requested offset and length against the allocated size.
* The invariants equation is: {@code 0 <= reqOff <= reqLen <= reqOff + reqLen <= allocSize}.
@@ -131,6 +116,7 @@ public abstract class BaseStateImpl implements BaseState {
* @param reqOff the requested offset
* @param reqLen the requested length
* @param allocSize the allocated size.
+ * @throws IllegalArgumentException for exceeding address bounds
*/
public static void checkBounds(final long reqOff, final long reqLen, final long allocSize) {
if ((reqOff | reqLen | (reqOff + reqLen) | (allocSize - (reqOff + reqLen))) < 0) {
@@ -159,6 +145,7 @@ public abstract class BaseStateImpl implements BaseState {
* Returns true if the given byteOrder is the same as the native byte order.
* @param byteOrder the given byte order
* @return true if the given byteOrder is the same as the native byte order.
+ * @throws IllegalArgumentException if ByteOrder is null
*/
public static boolean isNativeByteOrder(final ByteOrder byteOrder) {
if (byteOrder == null) {
@@ -188,14 +175,14 @@ public abstract class BaseStateImpl implements BaseState {
}
@Override
- public ByteBuffer toByteBuffer(ByteOrder order) {
+ public ByteBuffer toByteBuffer(final ByteOrder order) {
Objects.requireNonNull(order, "The input ByteOrder must not be null");
return ByteBuffer.wrap(seg.toByteArray());
}
@Override
public MemorySegment toMemorySegment() {
- MemorySegment arrSeg = MemorySegment.ofArray(new byte[(int)seg.byteSize()]);
+ final MemorySegment arrSeg = MemorySegment.ofArray(new byte[(int)seg.byteSize()]);
arrSeg.copyFrom(seg);
return arrSeg;
}
@@ -262,11 +249,11 @@ public abstract class BaseStateImpl implements BaseState {
return ((getTypeId() & READONLY) > 0) || seg.isReadOnly();
}
- final static int setReadOnlyType(final int type, final boolean readOnly) {
- return (type & ~READONLY) | (readOnly ? READONLY : 0);
- }
+ // final static int setReadOnlyType(final int type, final boolean readOnly) { //not used
+ // return (type & ~READONLY) | (readOnly ? READONLY : 0);
+ // }
- final boolean isRegionType() { //
+ final boolean isRegionType() {
return (getTypeId() & REGION) > 0;
}
@@ -274,15 +261,15 @@ public abstract class BaseStateImpl implements BaseState {
return (getTypeId() & DUPLICATE) > 0;
}
- final boolean isMemoryType() { //
+ final boolean isMemoryType() {
return (getTypeId() & BUFFER) == 0;
}
- final boolean isBufferType() { //
+ final boolean isBufferType() {
return (getTypeId() & BUFFER) > 0;
}
- final boolean isNativeType() { //
+ final boolean isNativeType() {
return (getTypeId() & NONNATIVE) == 0;
}
@@ -290,15 +277,15 @@ public abstract class BaseStateImpl implements BaseState {
return (getTypeId() & NONNATIVE) > 0;
}
- final boolean isHeapType() { //
+ final boolean isHeapType() { //test only
return (getTypeId() >>> 3 & 3) == 0;
}
- final boolean isDirectType() { //
+ final boolean isDirectType() { //test only
return (getTypeId() & DIRECT) > 0;
}
- final boolean isMapType() { //
+ final boolean isMapType() { //test only
return (getTypeId() & MAP) > 0;
}
@@ -412,6 +399,7 @@ public abstract class BaseStateImpl implements BaseState {
* Returns first two number groups of the java version string.
* @param jdkVer the java version string from System.getProperty("java.version").
* @return first two number groups of the java version string.
+ * @throws IllegalArgumentException for an improper Java version string.
*/
public static int[] parseJavaVersion(final String jdkVer) {
final int p0, p1;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index 8fab698..352bd85 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -25,7 +25,6 @@ import java.util.Objects;
import org.apache.datasketches.memory.Buffer;
import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.ReadOnlyException;
import org.apache.datasketches.memory.WritableBuffer;
import org.apache.datasketches.memory.WritableMemory;
@@ -60,21 +59,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
super(seg, typeId);
}
- //HEAP ARRAY RESOURCE
-
- public static WritableBuffer wrapSegmentAsArray(
- final MemorySegment seg,
- final ByteOrder byteOrder,
- final MemoryRequestServer memReqSvr) {
- int type = BUFFER
- | (seg.isReadOnly() ? READONLY : 0);
- if (byteOrder == ByteOrder.nativeOrder()) {
- type |= NATIVE;
- return new HeapWritableBufferImpl(seg, type, memReqSvr);
- }
- type |= NONNATIVE;
- return new HeapNonNativeWritableBufferImpl(seg, type, memReqSvr);
- }
+ //NO WRAP HEAP ARRAY RESOURCE
//BYTE BUFFER RESOURCE
@@ -84,7 +69,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
final ByteOrder byteOrder) {
final ByteBuffer byteBuf = localReadOnly ? byteBuffer.asReadOnlyBuffer() : byteBuffer.duplicate();
byteBuf.clear(); //resets position to zero and limit to capacity. Does not clear data.
- MemorySegment seg = MemorySegment.ofByteBuffer(byteBuf); //from 0 to capacity
+ final MemorySegment seg = MemorySegment.ofByteBuffer(byteBuf); //from 0 to capacity
int type = BUFFER | BYTEBUF
| (localReadOnly ? READONLY : 0)
| (seg.isNative() ? DIRECT : 0)
@@ -263,7 +248,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
WritableMemory wmem;
if (byteBufferType) {
if (nativeBOType) { wmem = new BBWritableMemoryImpl(seg2, type); }
- else { wmem = new BBNonNativeWritableMemoryImpl(seg2, type);}
+ else { wmem = new BBNonNativeWritableMemoryImpl(seg2, type); }
}
if (mapType) {
if (nativeBOType) { wmem = new MapWritableMemoryImpl(seg2, type); }
@@ -297,9 +282,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final void getByteArray(final byte[] dstArray, final int dstOffsetBytes,
final int lengthBytes) {
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetBytes, lengthBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetBytes, lengthBytes);
final long pos = getPosition();
- MemorySegment srcSlice = seg.asSlice(pos, lengthBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, lengthBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + lengthBytes);
}
@@ -335,9 +320,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final void putByteArray(final byte[] srcArray, final int srcOffsetBytes,
final int lengthBytes) {
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetBytes, lengthBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetBytes, lengthBytes);
final long pos = getPosition();
- MemorySegment dstSlice = seg.asSlice(pos, lengthBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, lengthBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + lengthBytes);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index e4527cc..74894f9 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -66,7 +66,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
super(seg, typeId);
}
- //HEAP ARRAY RESOURCE
+ //WRAP HEAP ARRAY RESOURCE
public static WritableMemory wrapSegmentAsArray(
final MemorySegment seg,
@@ -90,7 +90,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
final ByteOrder byteOrder) {
final ByteBuffer byteBuf = localReadOnly ? byteBuffer.asReadOnlyBuffer() : byteBuffer.duplicate();
byteBuf.clear(); //resets position to zero and limit to capacity. Does not clear data.
- MemorySegment seg = MemorySegment.ofByteBuffer(byteBuf); //from 0 to capacity
+ final MemorySegment seg = MemorySegment.ofByteBuffer(byteBuf); //from 0 to capacity
int type = MEMORY | BYTEBUF
| (localReadOnly ? READONLY : 0)
| (seg.isNative() ? DIRECT : 0)
@@ -115,7 +115,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
* @param localReadOnly the requested read-only state
* @param byteOrder the byte order to be used. It must be non-null.
* @return mapped WritableMemory.
- * @throws Exception
+ * @throws Exception for various IO exceptions
*/
@SuppressWarnings("resource")
public static WritableMemory wrapMap(
@@ -125,8 +125,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
final ResourceScope scope,
final boolean localReadOnly,
final ByteOrder byteOrder) throws Exception {
- FileChannel.MapMode mapMode = (localReadOnly) ? READ_ONLY : READ_WRITE;
- MemorySegment seg;
+ final FileChannel.MapMode mapMode = (localReadOnly) ? READ_ONLY : READ_WRITE;
+ final MemorySegment seg;
try {
seg = MemorySegment.mapFile(
file.toPath(),
@@ -298,8 +298,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
public final void getByteArray(final long offsetBytes, final byte[] dstArray,
final int dstOffsetBytes, final int lengthBytes) {
checkBounds(dstOffsetBytes, lengthBytes, dstArray.length);
- MemorySegment srcSlice = seg.asSlice(offsetBytes, lengthBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetBytes, lengthBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, lengthBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetBytes, lengthBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -328,7 +328,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
out.writeBytes(bArr);
}
-// //PRIMITIVE putX() and putXArray() implementations
+ // //PRIMITIVE putX() and putXArray() implementations
@Override
public final void putByte(final long offsetBytes, final byte value) {
@@ -338,12 +338,12 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void putByteArray(final long offsetBytes, final byte[] srcArray,
final int srcOffsetBytes, final int lengthBytes) {
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetBytes, lengthBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, lengthBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetBytes, lengthBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, lengthBytes);
dstSlice.copyFrom(srcSlice);
}
-// //OTHER WRITE METHODS
+ // OTHER WRITE METHODS
@Override
public final void clear() {
@@ -352,7 +352,7 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void clear(final long offsetBytes, final long lengthBytes) {
- MemorySegment slice = seg.asSlice(offsetBytes, lengthBytes);
+ final MemorySegment slice = seg.asSlice(offsetBytes, lengthBytes);
slice.fill((byte)0);
}
@@ -368,8 +368,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
}
@Override
- public final void fill(long offsetBytes, long lengthBytes, final byte value) {
- MemorySegment slice = seg.asSlice(offsetBytes, lengthBytes);
+ public final void fill(final long offsetBytes, final long lengthBytes, final byte value) {
+ final MemorySegment slice = seg.asSlice(offsetBytes, lengthBytes);
slice.fill(value);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
index 74a1dd1..921df11 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
@@ -36,7 +36,7 @@ final class CompareAndCopy {
final MemorySegment seg2, final long offsetBytes2, final long lengthBytes2) {
final MemorySegment slice1 = seg1.asSlice(offsetBytes1, lengthBytes1);
final MemorySegment slice2 = seg2.asSlice(offsetBytes2, lengthBytes2);
- long mm = slice1.mismatch(slice2);
+ final long mm = slice1.mismatch(slice2);
if (mm == -1) { return 0; }
if ((lengthBytes1 > mm) && (lengthBytes2 > mm)) {
return Integer.compare(
@@ -54,14 +54,14 @@ final class CompareAndCopy {
static boolean equals(
final MemorySegment seg1, final long offsetBytes1,
- final MemorySegment seg2, final long offsetBytes2, long lengthBytes) {
+ final MemorySegment seg2, final long offsetBytes2, final long lengthBytes) {
final MemorySegment slice1 = seg1.asSlice(offsetBytes1, lengthBytes);
final MemorySegment slice2 = seg2.asSlice(offsetBytes2, lengthBytes);
return slice1.mismatch(slice2) == -1;
}
static void copy(final MemorySegment srcSegment, final long srcOffsetBytes,
- MemorySegment dstSegment, final long dstOffsetBytes, final long lengthBytes) {
+ final MemorySegment dstSegment, final long dstOffsetBytes, final long lengthBytes) {
final MemorySegment srcSlice = srcSegment.asSlice(srcOffsetBytes, lengthBytes);
final MemorySegment dstSlice = dstSegment.asSlice(dstOffsetBytes, lengthBytes);
dstSlice.copyFrom(srcSlice);
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MurmurHash3v3.java b/src/main/java/org/apache/datasketches/memory/internal/MurmurHash3v3.java
index e53311b..c873120 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MurmurHash3v3.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MurmurHash3v3.java
@@ -60,6 +60,7 @@ public final class MurmurHash3v3 {
* @param in long array
* @param seed A long valued seed.
* @return the hash
+ * @throws IllegalArgumentException if input is empty or null
*/
public static long[] hash(final long[] in, final long seed) {
if ((in == null) || (in.length == 0)) {
@@ -75,6 +76,7 @@ public final class MurmurHash3v3 {
* @param in int array
* @param seed A long valued seed.
* @return the hash
+ * @throws IllegalArgumentException if input is empty or null
*/
public static long[] hash(final int[] in, final long seed) {
if ((in == null) || (in.length == 0)) {
@@ -90,6 +92,7 @@ public final class MurmurHash3v3 {
* @param in char array
* @param seed A long valued seed.
* @return the hash
+ * @throws IllegalArgumentException if input is empty or null
*/
public static long[] hash(final char[] in, final long seed) {
if ((in == null) || (in.length == 0)) {
@@ -105,6 +108,7 @@ public final class MurmurHash3v3 {
* @param in byte array
* @param seed A long valued seed.
* @return the hash
+ * @throws IllegalArgumentException if input is empty or null
*/
public static long[] hash(final byte[] in, final long seed) {
if ((in == null) || (in.length == 0)) {
@@ -152,6 +156,7 @@ public final class MurmurHash3v3 {
* @param seed A long valued seed.
* @param hashOut A long array of size 2
* @return the hash
+ * @throws IllegalArgumentException if input is empty or null
*/
public static long[] hash(final String in, final long seed, final long[] hashOut) {
if ((in == null) || (in.length() == 0)) {
@@ -177,7 +182,7 @@ public final class MurmurHash3v3 {
public static long[] hash(final Memory mem, final long offsetBytes, final long lengthBytes,
final long seed, final long[] hashOut) {
Objects.requireNonNull(mem, "Input Memory is null");
- MemorySegment seg = ((BaseStateImpl)mem).seg;
+ final MemorySegment seg = ((BaseStateImpl)mem).seg;
return hash(seg, offsetBytes, lengthBytes, seed, hashOut);
}
@@ -191,6 +196,7 @@ public final class MurmurHash3v3 {
* @param seed A long valued seed.
* @param hashOut the size 2 long array for the resulting 128-bit hash
* @return the hash.
+ * @throws IllegalArgumentException if input MemorySegment is empty
*/
public static long[] hash(final MemorySegment seg, final long offsetBytes, final long lengthBytes,
final long seed, final long[] hashOut) {
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
index cc298e7..8c0ab07 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
@@ -69,8 +69,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getCharArray(final char[] dstArray, final int dstOffsetChars, final int lengthChars) {
final long pos = getPosition();
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -91,8 +91,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getDoubleArray(final double[] dstArray, final int dstOffsetDoubles, final int lengthDoubles) {
final long pos = getPosition();
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -113,8 +113,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getFloatArray(final float[] dstArray, final int dstOffsetFloats, final int lengthFloats) {
final long pos = getPosition();
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -135,8 +135,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getIntArray(final int[] dstArray, final int dstOffsetInts, final int lengthInts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -157,8 +157,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getLongArray(final long[] dstArray, final int dstOffsetLongs, final int lengthLongs) {
final long pos = getPosition();
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -179,8 +179,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getShortArray(final short[] dstArray, final int dstOffsetShorts, final int lengthShorts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -202,8 +202,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putCharArray(final char[] srcArray, final int srcOffsetChars, final int lengthChars) {
final long pos = getPosition();
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -224,8 +224,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putDoubleArray(final double[] srcArray, final int srcOffsetDoubles, final int lengthDoubles) {
final long pos = getPosition();
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -246,8 +246,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putFloatArray(final float[] srcArray, final int srcOffsetFloats, final int lengthFloats) {
final long pos = getPosition();
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -268,8 +268,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putIntArray(final int[] srcArray, final int srcOffsetInts, final int lengthInts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -290,8 +290,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putLongArray(final long[] srcArray, final int srcOffsetLongs, final int lengthLongs) {
final long pos = getPosition();
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
@@ -313,8 +313,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthShorts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
dstSlice.copyFrom(srcSlice);
setPosition(pos + copyBytes);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
index f969a05..9b25510 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
@@ -61,8 +61,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getCharArray(final long offsetBytes, final char[] dstArray, final int dstOffsetChars,
final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -75,8 +75,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getDoubleArray(final long offsetBytes, final double[] dstArray,
final int dstOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -89,8 +89,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getFloatArray(final long offsetBytes, final float[] dstArray,
final int dstOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -103,8 +103,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getIntArray(final long offsetBytes, final int[] dstArray, final int dstOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -117,8 +117,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getLongArray(final long offsetBytes, final long[] dstArray,
final int dstOffsetLongs, final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -131,8 +131,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getShortArray(final long offsetBytes, final short[] dstArray,
final int dstOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -146,8 +146,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putCharArray(final long offsetBytes, final char[] srcArray,
final int srcOffsetChars, final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -160,8 +160,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putDoubleArray(final long offsetBytes, final double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -174,8 +174,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putFloatArray(final long offsetBytes, final float[] srcArray,
final int srcOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -188,8 +188,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putIntArray(final long offsetBytes, final int[] srcArray, final int srcOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -202,8 +202,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putLongArray(final long offsetBytes, final long[] srcArray, final int srcOffsetLongs,
final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
@@ -216,8 +216,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putShortArray(final long offsetBytes, final short[] srcArray,
final int srcOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
dstSlice.copyFrom(srcSlice);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
index 9330f86..39f9fb9 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
@@ -69,8 +69,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getCharArray(final char[] dstArray, final int dstOffsetChars, final int lengthChars) {
final long pos = getPosition();
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
for (int index = 0; index < lengthChars; index++) {
final char aChar = MemoryAccess.getCharAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setCharAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aChar);
@@ -95,8 +95,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthDoubles) {
final long pos = getPosition();
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
for (int index = 0; index < lengthDoubles; index++) {
final double dbl = MemoryAccess.getDoubleAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setDoubleAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, dbl);
@@ -121,8 +121,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthFloats) {
final long pos = getPosition();
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
for (int index = 0; index < lengthFloats; index++) {
final float flt = MemoryAccess.getFloatAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setFloatAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, flt);
@@ -146,8 +146,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getIntArray(final int[] dstArray, final int dstOffsetInts, final int lengthInts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
for (int index = 0; index < lengthInts; index++) {
final int anInt = MemoryAccess.getIntAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setIntAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, anInt);
@@ -171,8 +171,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void getLongArray(final long[] dstArray, final int dstOffsetLongs, final int lengthLongs) {
final long pos = getPosition();
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
for (int index = 0; index < lengthLongs; index++) {
final long aLong = MemoryAccess.getLongAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setLongAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aLong);
@@ -197,8 +197,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthShorts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
for (int index = 0; index < lengthShorts; index++) {
final short aShort = MemoryAccess.getShortAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setShortAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aShort);
@@ -223,8 +223,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putCharArray(final char[] srcArray, final int srcOffsetChars, final int lengthChars) {
final long pos = getPosition();
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthChars; index++) {
final char aChar = MemoryAccess.getCharAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setCharAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aChar);
@@ -249,8 +249,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthDoubles) {
final long pos = getPosition();
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthDoubles; index++) {
final double dbl = MemoryAccess.getDoubleAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setDoubleAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, dbl);
@@ -275,8 +275,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthFloats) {
final long pos = getPosition();
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthFloats; index++) {
final float flt = MemoryAccess.getFloatAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setFloatAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, flt);
@@ -300,8 +300,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putIntArray(final int[] srcArray, final int srcOffsetInts, final int lengthInts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthInts; index++) {
final int anInt = MemoryAccess.getIntAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setIntAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, anInt);
@@ -325,8 +325,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
public void putLongArray(final long[] srcArray, final int srcOffsetLongs, final int lengthLongs) {
final long pos = getPosition();
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthLongs; index++) {
final long aLong = MemoryAccess.getLongAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setLongAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aLong);
@@ -351,8 +351,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
final int lengthShorts) {
final long pos = getPosition();
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(pos, copyBytes);
for (int index = 0; index < lengthShorts; index++) {
final short aShort = MemoryAccess.getShortAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setShortAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aShort);
diff --git a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
index eb3ce8b..711903c 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
@@ -61,8 +61,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getCharArray(final long offsetBytes, final char[] dstArray,
final int dstOffsetChars, final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetChars << CHAR_SHIFT, copyBytes);
for (int index = 0; index < lengthChars; index++) {
final char aChar = MemoryAccess.getCharAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setCharAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aChar);
@@ -78,8 +78,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getDoubleArray(final long offsetBytes, final double[] dstArray,
final int dstOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetDoubles << DOUBLE_SHIFT, copyBytes);
for (int index = 0; index < lengthDoubles; index++) {
final double dbl = MemoryAccess.getDoubleAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setDoubleAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, dbl);
@@ -95,8 +95,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getFloatArray(final long offsetBytes, final float[] dstArray,
final int dstOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetFloats << FLOAT_SHIFT, copyBytes);
for (int index = 0; index < lengthFloats; index++) {
final float flt = MemoryAccess.getFloatAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setFloatAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, flt);
@@ -112,8 +112,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getIntArray(final long offsetBytes, final int[] dstArray, final int dstOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetInts << INT_SHIFT, copyBytes);
for (int index = 0; index < lengthInts; index++) {
final int anInt = MemoryAccess.getIntAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setIntAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, anInt);
@@ -129,8 +129,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getLongArray(final long offsetBytes, final long[] dstArray,
final int dstOffsetLongs, final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetLongs << LONG_SHIFT, copyBytes);
for (int index = 0; index < lengthLongs; index++) {
final long aLong = MemoryAccess.getLongAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setLongAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aLong);
@@ -146,8 +146,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getShortArray(final long offsetBytes, final short[] dstArray,
final int dstOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
- MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment srcSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment dstSlice = MemorySegment.ofArray(dstArray).asSlice(dstOffsetShorts << SHORT_SHIFT, copyBytes);
for (int index = 0; index < lengthShorts; index++) {
final short aShort = MemoryAccess.getShortAtIndex(srcSlice, index, NON_NATIVE_BYTE_ORDER);
MemoryAccess.setShortAtIndex(dstSlice, index, NATIVE_BYTE_ORDER, aShort);
@@ -164,8 +164,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putCharArray(final long offsetBytes, final char[] srcArray, final int srcOffsetChars,
final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetChars << CHAR_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthChars; index++) {
final char aChar = MemoryAccess.getCharAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setCharAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aChar);
@@ -181,8 +181,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putDoubleArray(final long offsetBytes, final double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetDoubles << DOUBLE_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthDoubles; index++) {
final double dbl = MemoryAccess.getDoubleAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setDoubleAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, dbl);
@@ -198,8 +198,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putFloatArray(final long offsetBytes, final float[] srcArray,
final int srcOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetFloats << FLOAT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthFloats; index++) {
final float flt = MemoryAccess.getFloatAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setFloatAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, flt);
@@ -215,8 +215,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putIntArray(final long offsetBytes, final int[] srcArray, final int srcOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetInts << INT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthInts; index++) {
final int anInt = MemoryAccess.getIntAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setIntAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, anInt);
@@ -232,8 +232,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putLongArray(final long offsetBytes, final long[] srcArray, final int srcOffsetLongs,
final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetLongs << LONG_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthLongs; index++) {
final long aLong = MemoryAccess.getLongAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setLongAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aLong);
@@ -249,8 +249,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putShortArray(final long offsetBytes, final short[] srcArray,
final int srcOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
- MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
+ final MemorySegment srcSlice = MemorySegment.ofArray(srcArray).asSlice(srcOffsetShorts << SHORT_SHIFT, copyBytes);
+ final MemorySegment dstSlice = seg.asSlice(offsetBytes, copyBytes);
for (int index = 0; index < lengthShorts; index++) {
final short aShort = MemoryAccess.getShortAtIndex(srcSlice, index, NATIVE_BYTE_ORDER);
MemoryAccess.setShortAtIndex(dstSlice, index, NON_NATIVE_BYTE_ORDER, aShort);
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Util.java b/src/main/java/org/apache/datasketches/memory/internal/Util.java
index b66b17f..12cfc26 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -90,6 +90,7 @@ public final class Util {
*
* @param shortFileName the last name in the pathname's name sequence.
* @return the absolute path of the given resource file's shortName.
+ * @throws IllegalArgumentException if resource cannot be found
*/
public static String getResourcePath(final String shortFileName) {
Objects.requireNonNull(shortFileName, "input parameter " + shortFileName + " cannot be null.");
@@ -115,11 +116,10 @@ public final class Util {
}
/**
- * Returns a byte array of the contents of the file defined by the given resource file's
- * shortFileName.
+ * Returns a byte array of the contents of the file defined by the given resource file's shortFileName.
* @param shortFileName the last name in the pathname's name sequence.
- * @return a byte array of the contents of the file defined by the given resource file's
- * shortFileName.
+ * @return a byte array of the contents of the file defined by the given resource file's shortFileName.
+ * @throws IllegalArgumentException if resource cannot be read.
*/
public static byte[] getResourceBytes(final String shortFileName) {
try {
diff --git a/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java b/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
index 76ce3e0..994cb02 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/XxHash64.java
@@ -19,13 +19,16 @@
package org.apache.datasketches.memory.internal;
+import static jdk.incubator.foreign.MemoryAccess.getByteAtOffset;
+import static jdk.incubator.foreign.MemoryAccess.getIntAtOffset;
+import static jdk.incubator.foreign.MemoryAccess.getLongAtOffset;
import static org.apache.datasketches.memory.internal.BaseStateImpl.CHAR_SHIFT;
import static org.apache.datasketches.memory.internal.BaseStateImpl.DOUBLE_SHIFT;
import static org.apache.datasketches.memory.internal.BaseStateImpl.FLOAT_SHIFT;
import static org.apache.datasketches.memory.internal.BaseStateImpl.INT_SHIFT;
import static org.apache.datasketches.memory.internal.BaseStateImpl.LONG_SHIFT;
import static org.apache.datasketches.memory.internal.BaseStateImpl.SHORT_SHIFT;
-import static jdk.incubator.foreign.MemoryAccess.*;
+
import jdk.incubator.foreign.MemorySegment;
/**
@@ -196,7 +199,7 @@ public class XxHash64 {
*/
public static long hashBytes(final byte[] arr, final int offsetBytes,
final int lengthBytes, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetBytes, lengthBytes, seed);
}
@@ -211,7 +214,7 @@ public class XxHash64 {
*/
public static long hashShorts(final short[] arr, final int offsetShorts,
final int lengthShorts, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, (offsetShorts << SHORT_SHIFT), lengthShorts << SHORT_SHIFT, seed);
}
@@ -226,7 +229,7 @@ public class XxHash64 {
*/
public static long hashChars(final char[] arr, final int offsetChars,
final int lengthChars, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetChars << CHAR_SHIFT, lengthChars << CHAR_SHIFT, seed);
}
@@ -241,7 +244,7 @@ public class XxHash64 {
*/
public static long hashInts(final int[] arr, final int offsetInts,
final int lengthInts, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetInts << INT_SHIFT, lengthInts << INT_SHIFT, seed);
}
@@ -256,7 +259,7 @@ public class XxHash64 {
*/
public static long hashLongs(final long[] arr, final int offsetLongs,
final int lengthLongs, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetLongs << LONG_SHIFT, lengthLongs << LONG_SHIFT, seed);
}
@@ -271,7 +274,7 @@ public class XxHash64 {
*/
public static long hashFloats(final float[] arr, final int offsetFloats,
final int lengthFloats, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetFloats << FLOAT_SHIFT, lengthFloats << FLOAT_SHIFT, seed);
}
@@ -286,7 +289,7 @@ public class XxHash64 {
*/
public static long hashDoubles(final double[] arr, final int offsetDoubles,
final int lengthDoubles, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(arr);
+ final MemorySegment seg = MemorySegment.ofArray(arr);
return hash(seg, offsetDoubles << DOUBLE_SHIFT, lengthDoubles << DOUBLE_SHIFT, seed);
}
@@ -301,7 +304,7 @@ public class XxHash64 {
*/
public static long hashString(final String str, final int offsetChars,
final int lengthChars, final long seed) {
- MemorySegment seg = MemorySegment.ofArray(str.toCharArray());
+ final MemorySegment seg = MemorySegment.ofArray(str.toCharArray());
return hash(seg, offsetChars << CHAR_SHIFT, lengthChars << CHAR_SHIFT, seed);
}
diff --git a/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java b/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
index d0cf39a..d882cfe 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
@@ -98,7 +98,12 @@ public class BaseStateTest {
println(buf.toHexString("buffer", 0, 16, true));
}
-
+ @Test
+ public void checkToMemorySegment() {
+ WritableMemory mem = WritableMemory.allocate(8);
+ mem.toMemorySegment();
+ mem.asByteBufferView(ByteOrder.nativeOrder());
+ }
/********************/
@Test
diff --git a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index 8404398..85dead1 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -172,6 +172,36 @@ public class MemoryTest {
}
}
+ @Test
+ public void checkByteBufferNonNativeHeap() {
+ int n = 10; //longs
+ byte[] arr = new byte[n * 8];
+ ByteBuffer bb = ByteBuffer.wrap(arr); //non-native order
+ WritableMemory wmem = WritableMemory.writableWrap(bb, BaseState.NON_NATIVE_BYTE_ORDER);
+ for (int i = 0; i < n; i++) { //write to wmem
+ wmem.putLong(i * 8, i);
+ }
+ for (int i = 0; i < n; i++) { //read from wmem
+ long v = wmem.getLong(i * 8);
+ assertEquals(v, i);
+ }
+ for (int i = 0; i < n; i++) { //read from BB
+ long v = bb.getLong(i * 8);
+ assertEquals(v, i);
+ }
+ Memory mem1 = Memory.wrap(arr, BaseState.NON_NATIVE_BYTE_ORDER);
+ for (int i = 0; i < n; i++) { //read from wrapped arr
+ long v = mem1.getLong(i * 8);
+ assertEquals(v, i);
+ }
+ //convert to RO
+ Memory mem = wmem;
+ for (int i = 0; i < n; i++) {
+ long v = mem.getLong(i * 8);
+ assertEquals(v, i);
+ }
+ }
+
@Test
public void checkByteBufDirect() {
int n = 1024; //longs
diff --git a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
index 07fdbdb..7f81a64 100644
--- a/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
+++ b/src/test/java/org/apache/datasketches/memory/internal/SpecificLeafTest.java
@@ -52,8 +52,12 @@ public class SpecificLeafTest {
Memory mem = Memory.wrap(bb).region(0, bytes, ByteOrder.nativeOrder());
assertTrue(mem.hasByteBuffer());
assertTrue(mem.isReadOnly());
+ assertTrue(((BaseStateImpl)mem).isMemoryType());
+ assertFalse(((BaseStateImpl)mem).isDirectType());
+ assertFalse(((BaseStateImpl)mem).isMapType());
checkCrossLeafTypeIds(mem);
Buffer buf = mem.asBuffer().region(0, bytes, ByteOrder.nativeOrder());
+ assertTrue(((BaseStateImpl)buf).isNativeType());
bb.order(BaseState.NON_NATIVE_BYTE_ORDER);
Memory mem2 = Memory.wrap(bb).region(0, bytes, BaseState.NON_NATIVE_BYTE_ORDER);
@@ -72,7 +76,9 @@ public class SpecificLeafTest {
int bytes = 128;
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
WritableMemory wmem = WritableMemory.allocateDirect(bytes, scope, memReqSvr);
+ assertFalse(((BaseStateImpl)wmem).isReadOnly());
assertTrue(((BaseStateImpl)wmem).isDirectType());
+ assertFalse(((BaseStateImpl)wmem).isHeapType());
assertFalse(wmem.isReadOnly());
checkCrossLeafTypeIds(wmem);
WritableMemory nnwmem = wmem.writableRegion(0, bytes, BaseState.NON_NATIVE_BYTE_ORDER);
@@ -87,6 +93,7 @@ public class SpecificLeafTest {
assertTrue(((BaseStateImpl)mem).isRegionType());
assertTrue(((BaseStateImpl)mem2).isRegionType());
+ assertTrue(((BaseStateImpl)mem2).isMemoryType());
assertTrue(((BaseStateImpl)buf).isRegionType());
assertTrue(((BaseStateImpl)buf2).isRegionType());
assertTrue(((BaseStateImpl)buf3).isDuplicateType());
@@ -126,7 +133,9 @@ public class SpecificLeafTest {
assertTrue(((BaseStateImpl)reg).isRegionType());
assertTrue(((BaseStateImpl)reg2).isRegionType());
+ assertFalse(((BaseStateImpl)reg2).isNativeType());
assertTrue(((BaseStateImpl)buf).isRegionType());
+ assertFalse(((BaseStateImpl)buf).isMemoryType());
assertTrue(((BaseStateImpl)buf2).isRegionType());
assertTrue(((BaseStateImpl)buf3).isDuplicateType());
assertTrue(((BaseStateImpl)buf4).isDuplicateType());
diff --git a/tools/MemoryCheckstyle.xml b/tools/MemoryCheckstyle.xml
index 93c3bf3..377393f 100644
--- a/tools/MemoryCheckstyle.xml
+++ b/tools/MemoryCheckstyle.xml
@@ -41,6 +41,11 @@ under the License.
<property name="fileNamePattern" value="src[\\/]test[\\/]java[\\/].+$|module\-info\.java.+$"/>
</module>
+ <!-- Excludes all 'module-info.java' files -->
+ <module name="BeforeExecutionExclusionFileFilter">
+ <property name="fileNamePattern" value="module\-info\.java$"/>
+ </module>
+
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
@@ -200,10 +205,11 @@ under the License.
</module>
<module name="JavadocMethod">
- <property name="scope" value="public"/>
+ <property name="allowedAnnotations" value="Override, Test"/>
+ <property name="validateThrows" value="true"/>
+ <property name="accessModifiers" value="public"/>
<property name="allowMissingParamTags" value="false"/> <!-- default -->
<property name="allowMissingReturnTag" value="false"/> <!-- default -->
- <property name="allowedAnnotations" value="Override, Test"/>
</module>
<module name="JavadocParagraph"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org