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 2021/05/18 19:57:13 UTC
[datasketches-memory] 06/08: Interim commit. Completed refactoring
of Memory hierarchy.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch CreateInternal2
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit a43140dabcafa4f97f112282d1a06e28db1ea059
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon May 17 16:48:52 2021 -0700
Interim commit. Completed refactoring of Memory hierarchy.
Buffer hierarchy is not done, many errors in test. Main compiles clean,
no warnings.
---
.../memory/DefaultMemoryRequestServer.java | 4 +-
.../org/apache/datasketches/memory/Handle.java | 4 -
.../org/apache/datasketches/memory/Memory.java | 525 ++++++++++++++++++++-
.../datasketches/memory/MemoryRequestServer.java | 2 -
.../datasketches/memory/WritableDirectHandle.java | 2 +-
.../apache/datasketches/memory/WritableHandle.java | 5 +-
...WritableMemoryImpl.java => WritableMemory.java} | 216 ++++-----
.../memory/internal/AllocateDirect.java | 2 +-
.../memory/internal/AllocateDirectMap.java | 5 +-
.../memory/internal/AllocateDirectWritableMap.java | 6 +-
.../internal/BBNonNativeWritableMemoryImpl.java | 2 +-
.../memory/internal/BBWritableMemoryImpl.java | 4 +-
.../memory/internal/BaseStateImpl.java | 20 +-
.../memory/internal/BaseWritableBufferImpl.java | 8 +-
.../memory/internal/BaseWritableMemoryImpl.java | 30 +-
.../datasketches/memory/internal/Buffer.java | 30 +-
.../memory/internal/CompareAndCopy.java | 2 +-
.../DirectNonNativeWritableBufferImpl.java | 2 +-
.../DirectNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/DirectWritableBufferImpl.java | 2 +-
.../memory/internal/DirectWritableMemoryImpl.java | 4 +-
.../internal/HeapNonNativeWritableMemoryImpl.java | 2 +-
.../memory/internal/HeapWritableMemoryImpl.java | 4 +-
.../memory/internal/MapHandleImpl.java | 6 +-
.../internal/MapNonNativeWritableBufferImpl.java | 2 +-
.../internal/MapNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/MapWritableBufferImpl.java | 2 +-
.../memory/internal/MapWritableMemoryImpl.java | 6 +-
.../datasketches/memory/internal/MemoryImpl.java | 446 ++---------------
.../memory/internal/NativeWritableMemoryImpl.java | 6 +-
.../internal/NonNativeWritableMemoryImpl.java | 4 +-
.../apache/datasketches/memory/internal/Utf8.java | 8 +-
.../memory/internal/Utf8CodingException.java | 2 +-
.../apache/datasketches/memory/internal/Util.java | 6 +-
.../memory/internal/WritableBuffer.java | 34 +-
.../memory/internal/WritableDirectHandleImpl.java | 15 +-
.../memory/internal/WritableMapHandleImpl.java | 5 +-
.../memory/internal/WritableMemoryImpl.java | 520 +++-----------------
.../datasketches/memory/internal/package-info.java | 36 +-
.../memory/test/AllocateDirectMapMemoryTest.java | 26 +-
.../memory/test/AllocateDirectMemoryTest.java | 22 +-
.../test/AllocateDirectWritableMapMemoryTest.java | 36 +-
.../datasketches/memory/test/BaseBufferTest.java | 14 +-
.../datasketches/memory/test/BaseStateTest.java | 14 +-
.../datasketches/memory/test/Buffer2Test.java | 32 +-
.../memory/test/BufferBoundaryCheckTest.java | 4 +-
.../memory/test/BufferInvariantsTest.java | 12 +-
.../memory/test/BufferReadWriteSafetyTest.java | 8 +-
.../datasketches/memory/test/BufferTest.java | 56 +--
.../datasketches/memory/test/CommonBufferTest.java | 22 +-
.../datasketches/memory/test/CommonMemoryTest.java | 44 +-
.../memory/test/CopyMemoryOverlapTest.java | 26 +-
.../datasketches/memory/test/CopyMemoryTest.java | 56 +--
.../test/ExampleMemoryRequestServerTest.java | 28 +-
.../memory/test/IgnoredArrayOverflowTest.java | 6 +-
.../datasketches/memory/test/LeafImplTest.java | 32 +-
.../memory/test/MemoryBoundaryCheckTest.java | 4 +-
.../memory/test/MemoryReadWriteSafetyTest.java | 42 +-
.../datasketches/memory/test/MemoryTest.java | 156 +++---
.../memory/test/MemoryWriteToTest.java | 22 +-
.../datasketches/memory/test/NioBitsTest.java | 2 +-
.../test/NonNativeWritableBufferImplTest.java | 30 +-
.../test/NonNativeWritableMemoryImplTest.java | 36 +-
.../datasketches/memory/test/SpecificLeafTest.java | 44 +-
.../apache/datasketches/memory/test/Utf8Test.java | 50 +-
.../apache/datasketches/memory/test/UtilTest.java | 4 +-
.../memory/test/WritableBufferImplTest.java | 104 ++--
.../memory/test/WritableDirectCopyTest.java | 66 +--
.../memory/test/WritableMemoryImplTest.java | 176 +++----
.../memory/test/WritableMemoryTest.java | 48 +-
.../memory/test/XxHash64LoopingTest.java | 4 +-
.../datasketches/memory/test/XxHash64Test.java | 14 +-
.../datasketches/memory/test/ZeroCapacityTest.java | 16 +-
73 files changed, 1483 insertions(+), 1760 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java b/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
index 607995f..a870b9b 100644
--- a/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
+++ b/src/main/java/org/apache/datasketches/memory/DefaultMemoryRequestServer.java
@@ -19,7 +19,7 @@
package org.apache.datasketches.memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
/**
* This is a simple implementation of the MemoryRequestServer that creates space on the Java heap
@@ -75,7 +75,7 @@ public final class DefaultMemoryRequestServer implements MemoryRequestServer {
*/
@Override
public WritableMemory request(final long capacityBytes) {
- final WritableMemory wmem = WritableMemory.allocate((int)capacityBytes);
+ final WritableMemory wmem = WritableMemoryImpl.allocate((int)capacityBytes);
return wmem;
}
diff --git a/src/main/java/org/apache/datasketches/memory/Handle.java b/src/main/java/org/apache/datasketches/memory/Handle.java
index f92b284..c541282 100644
--- a/src/main/java/org/apache/datasketches/memory/Handle.java
+++ b/src/main/java/org/apache/datasketches/memory/Handle.java
@@ -19,8 +19,6 @@
package org.apache.datasketches.memory;
-import org.apache.datasketches.memory.internal.Memory;
-
/**
* A handle for read-only resource.
*
@@ -58,6 +56,4 @@ public interface Handle extends AutoCloseable {
*/
Memory get();
- @Override
- void close();
}
diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java b/src/main/java/org/apache/datasketches/memory/Memory.java
index b170ad9..01d7891 100644
--- a/src/main/java/org/apache/datasketches/memory/Memory.java
+++ b/src/main/java/org/apache/datasketches/memory/Memory.java
@@ -20,8 +20,531 @@
package org.apache.datasketches.memory;
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.WritableByteChannel;
-public interface Memory {
+import org.apache.datasketches.memory.internal.Buffer;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.Utf8CodingException;
+import org.apache.datasketches.memory.internal.Util;
+
+public interface Memory extends BaseState {
+
+ //BYTE BUFFER
+
+ /**
+ * Accesses the given ByteBuffer for read-only operations. The returned <i>MemoryImpl</i> object has
+ * the same byte order, as the given ByteBuffer, unless the capacity of the given ByteBuffer is
+ * zero, then byte order of the returned <i>Memory</i> object (as well as backing storage) is
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param byteBuf the given ByteBuffer, must not be null
+ * @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
+ */
+ static Memory wrap(final ByteBuffer byteBuf) {
+ return MemoryImpl.wrap(byteBuf);
+ }
+
+ /**
+ * Accesses the given ByteBuffer for read-only operations. The returned <i>Memory</i> object has
+ * the given byte order, ignoring the byte order of the given ByteBuffer. If the capacity of the
+ * given ByteBuffer is zero the byte order of the returned <i>Memory</i> object (as well as
+ * backing storage) is unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param byteBuf the given ByteBuffer, must not be null
+ * @param byteOrder the byte order to be used, whicn may be independent of the byte order
+ * state of the given ByteBuffer.
+ * @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
+ */
+ static Memory wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ return MemoryImpl.wrap(byteBuf, byteOrder);
+ }
+
+ //MAP
+ /**
+ * Maps the entire given file into native-ordered Memory for read operations
+ * (including those > 2GB).
+ * Calling this method is equivalent to calling {@link #map(File, long, long, ByteOrder)
+ * map(file, 0, file.length(), ByteOrder.nativeOrder())}.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.map(...)</i>.
+ * @param file the given file to map
+ * @return <i>MapHandle</i> for managing the mapped Memory.
+ * Please read Javadocs for {@link Handle}.
+ */
+ static MapHandle map(final File file) {
+ return MemoryImpl.map(file, 0, file.length(), ByteOrder.nativeOrder());
+ }
+
+ /**
+ * Maps the specified portion of the given file into Memory for read operations
+ * (including those > 2GB).
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.map(...)</i>.
+ * @param file the given file to map. It may not be null.
+ * @param fileOffsetBytes the position in the given file in bytes. It may not be negative.
+ * @param capacityBytes the size of the mapped Memory. It may not be negative or zero.
+ * @param byteOrder the byte order to be used for the mapped Memory. It may not be null.
+ * @return <i>MapHandle</i> for managing the mapped Memory.
+ * Please read Javadocs for {@link Handle}.
+ */
+ static MapHandle map(final File file, final long fileOffsetBytes, final long capacityBytes,
+ final ByteOrder byteOrder) {
+ return MemoryImpl.map(file, fileOffsetBytes, capacityBytes, byteOrder);
+ }
+
+ //REGIONS
+ /**
+ * A region is a read-only view of this object.
+ * <ul>
+ * <li>Returned object's origin = this object's origin + offsetBytes</li>
+ * <li>Returned object's capacity = capacityBytes</li>
+ * </ul>
+ * If the given capacityBytes is zero, the returned object is effectively immutable and
+ * the backing storage and byte order are unspecified.
+ * @param offsetBytes the starting offset with respect to the origin of this Memory.
+ * @param capacityBytes the capacity of the region in bytes
+ * @return a new <i>Memory</i> representing the defined region based on the given
+ * offsetBytes and capacityBytes.
+ */
+ MemoryImpl region(long offsetBytes, long capacityBytes);
+
+ /**
+ * A region is a read-only view of this object.
+ * <ul>
+ * <li>Returned object's origin = this object's origin + <i>offsetBytes</i></li>
+ * <li>Returned object's capacity = <i>capacityBytes</i></li>
+ * <li>Returned object's byte order = <i>byteOrder</i></li>
+ * </ul>
+ * If the given capacityBytes is zero, the returned object is effectively immutable and
+ * the backing storage and byte order are unspecified.
+ * @param offsetBytes the starting offset with respect to the origin of this Memory.
+ * @param capacityBytes the capacity of the region in bytes
+ * @param byteOrder the given byte order
+ * @return a new <i>Memory</i> representing the defined region based on the given
+ * offsetBytes, capacityBytes and byteOrder.
+ */
+ MemoryImpl region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+
+ //AS BUFFER
+ /**
+ * Returns a new <i>Buffer</i> view of this object.
+ * <ul>
+ * <li>Returned object's origin = this object's origin</li>
+ * <li>Returned object's <i>start</i> = 0</li>
+ * <li>Returned object's <i>position</i> = 0</li>
+ * <li>Returned object's <i>end</i> = this object's capacity</li>
+ * <li>Returned object's <i>capacity</i> = this object's capacity</li>
+ * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
+ * </ul>
+ * If this object's capacity is zero, the returned object is effectively immutable and
+ * the backing storage and byte order are unspecified.
+ * @return a new <i>Buffer</i>
+ */
+ Buffer asBuffer();
+
+ /**
+ * Returns a new <i>Buffer</i> view of this object, with the given
+ * byte order.
+ * <ul>
+ * <li>Returned object's origin = this object's origin</li>
+ * <li>Returned object's <i>start</i> = 0</li>
+ * <li>Returned object's <i>position</i> = 0</li>
+ * <li>Returned object's <i>end</i> = this object's capacity</li>
+ * <li>Returned object's <i>capacity</i> = this object's capacity</li>
+ * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
+ * </ul>
+ * If this object's capacity is zero, the returned object is effectively immutable and
+ * the backing storage and byte order are unspecified.
+ * @param byteOrder the given byte order
+ * @return a new <i>Buffer</i> with the given byteOrder.
+ */
+ Buffer asBuffer(ByteOrder byteOrder);
+
+ //UNSAFE BYTE BUFFER VIEW
+ /**
+ * Returns the specified region of this Memory object as a new read-only {@link ByteBuffer}
+ * object. The {@link ByteOrder} of the returned {@code ByteBuffer} corresponds to the {@linkplain
+ * #getTypeByteOrder() byte order of this Memory}. The returned ByteBuffer's position is 0 and
+ * the limit is equal to the capacity.
+ *
+ * <p>If this Memory object is the result of wrapping non-byte Java arrays ({@link
+ * Memory#wrap(int[])}, {@link Memory#wrap(long[])}, etc.) this methods throws an {@link
+ * UnsupportedOperationException}.
+ *
+ * <p>The name of this method starts with "unsafe" because if this is a native managed Memory
+ * (e. g. obtained via {@link #map(File)} or {@link WritableMemory#allocateDirect(long)})), and
+ * the returned {@code ByteBuffer} object is used after the Memory is freed, it may cause a JVM
+ * crash. This is also possible for Memory objects themselves with some methods,
+ * but Memory's use-after-free is caught as an AssertionError, if assertions are enabled.
+ *
+ * @param offsetBytes the starting offset with respect to the origin of this Memory
+ * @param capacityBytes the capacity of the returned ByteBuffer
+ * @return a new read-only {@code ByteBuffer} to access the specified region.
+ * @throws UnsupportedOperationException if this method couldn't be viewed as ByteBuffer, because
+ * when it wraps a non-byte Java array.
+ */
+ ByteBuffer unsafeByteBufferView(long offsetBytes, int capacityBytes);
+
+ //ACCESS PRIMITIVE HEAP ARRAYS for readOnly
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final boolean[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>MemoryImpl</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final byte[] arr) {
+ return MemoryImpl.wrap(arr, 0, arr.length, Util.nativeByteOrder);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations with the given byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @param byteOrder the byte order to be used
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final byte[] arr, final ByteOrder byteOrder) {
+ return MemoryImpl.wrap(arr, 0, arr.length, byteOrder);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations with the given byte order. If the given
+ * lengthBytes is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @param offsetBytes the byte offset into the given array
+ * @param lengthBytes the number of bytes to include from the given array
+ * @param byteOrder the byte order to be used
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
+ final ByteOrder byteOrder) {
+ return MemoryImpl.wrap(arr, offsetBytes, lengthBytes, byteOrder);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final char[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final short[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final int[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final long[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final float[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ /**
+ * Wraps the given primitive array for read operations assuming native byte order. If the array
+ * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
+ * unspecified.
+ *
+ * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
+ * <i>Memory.wrap(...)</i>.
+ * @param arr the given primitive array.
+ * @return a new <i>Memory</i> for read operations
+ */
+ static Memory wrap(final double[] arr) {
+ return MemoryImpl.wrap(arr);
+ }
+
+ //PRIMITIVE getX() and getXArray()
+ /**
+ * Gets the boolean value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the boolean at the given offset
+ */
+ boolean getBoolean(long offsetBytes);
+
+ /**
+ * Gets the boolean array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetBooleans offset in array units
+ * @param lengthBooleans number of array units to transfer
+ */
+ void getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans);
+
+ /**
+ * Gets the byte value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the byte at the given offset
+ */
+ byte getByte(long offsetBytes);
+
+ /**
+ * Gets the byte array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetBytes offset in array units
+ * @param lengthBytes number of array units to transfer
+ */
+ void getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes);
+
+ /**
+ * Gets the char value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the char at the given offset
+ */
+ char getChar(long offsetBytes);
+
+ /**
+ * Gets the char array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetChars offset in array units
+ * @param lengthChars number of array units to transfer
+ */
+ void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars);
+
+ /**
+ * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
+ * utf8LengthBytes, decodes them into characters and appends them to the given Appendable.
+ * This is specifically designed to reduce the production of intermediate objects (garbage),
+ * thus significantly reducing pressure on the JVM Garbage Collector.
+ * @param offsetBytes offset bytes relative to the Memory start
+ * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
+ * caller has the correct number of utf8 bytes required to decode the number of characters
+ * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
+ * character to decode.
+ * @param dst the destination Appendable to append the decoded characters to.
+ * @return the number of characters decoded
+ * @throws IOException if dst.append() throws IOException
+ * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
+ */
+ int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst)
+ throws IOException, Utf8CodingException;
+
+ /**
+ * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
+ * utf8LengthBytes, decodes them into characters and appends them to the given StringBuilder.
+ * This method does *not* reset the length of the destination StringBuilder before appending
+ * characters to it.
+ * This is specifically designed to reduce the production of intermediate objects (garbage),
+ * thus significantly reducing pressure on the JVM Garbage Collector.
+ * @param offsetBytes offset bytes relative to the Memory start
+ * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
+ * caller has the correct number of utf8 bytes required to decode the number of characters
+ * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
+ * character to decode.
+ * @param dst the destination StringBuilder to append decoded characters to.
+ * @return the number of characters decoded.
+ * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
+ */
+ int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
+ final StringBuilder dst) throws Utf8CodingException;
+
+ /**
+ * Gets the double value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the double at the given offset
+ */
+ double getDouble(long offsetBytes);
+
+ /**
+ * Gets the double array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetDoubles offset in array units
+ * @param lengthDoubles number of array units to transfer
+ */
+ void getDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles, int lengthDoubles);
+
+ /**
+ * Gets the float value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the float at the given offset
+ */
+ float getFloat(long offsetBytes);
+
+ /**
+ * Gets the float array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetFloats offset in array units
+ * @param lengthFloats number of array units to transfer
+ */
+ void getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats);
+
+ /**
+ * Gets the int value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the int at the given offset
+ */
+ int getInt(long offsetBytes);
+
+ /**
+ * Gets the int array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetInts offset in array units
+ * @param lengthInts number of array units to transfer
+ */
+ void getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts);
+
+ /**
+ * Gets the long value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the long at the given offset
+ */
+ long getLong(long offsetBytes);
+
+ /**
+ * Gets the long array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetLongs offset in array units
+ * @param lengthLongs number of array units to transfer
+ */
+ void getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs);
+
+ /**
+ * Gets the short value at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @return the short at the given offset
+ */
+ short getShort(long offsetBytes);
+
+ /**
+ * Gets the short array at the given offset
+ * @param offsetBytes offset bytes relative to this Memory start
+ * @param dstArray The preallocated destination array.
+ * @param dstOffsetShorts offset in array units
+ * @param lengthShorts number of array units to transfer
+ */
+ void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts);
+
+ //SPECIAL PRIMITIVE READ METHODS: compareTo, copyTo, writeTo
+ /**
+ * Compares the bytes of this Memory to <i>that</i> Memory.
+ * Returns <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
+ * : 0;</i>.
+ * If all bytes are equal up to the shorter of the two lengths, the shorter length is considered
+ * to be less than the other.
+ * @param thisOffsetBytes the starting offset for <i>this Memory</i>
+ * @param thisLengthBytes the length of the region to compare from <i>this Memory</i>
+ * @param that the other Memory to compare with
+ * @param thatOffsetBytes the starting offset for <i>that Memory</i>
+ * @param thatLengthBytes the length of the region to compare from <i>that Memory</i>
+ * @return <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
+ * : 0;</i>
+ */
+ int compareTo(long thisOffsetBytes, long thisLengthBytes, Memory that,
+ long thatOffsetBytes, long thatLengthBytes);
+
+ /**
+ * Copies bytes from a source range of this Memory to a destination range of the given Memory
+ * with the same semantics when copying between overlapping ranges of bytes as method
+ * {@link java.lang.System#arraycopy(Object, int, Object, int, int)} has. However, if the source
+ * and the destination ranges are exactly the same, this method throws {@link
+ * IllegalArgumentException}, because it should never be needed in real-world scenarios and
+ * therefore indicates a bug.
+ * @param srcOffsetBytes the source offset for this Memory
+ * @param destination the destination Memory, which may not be Read-Only.
+ * @param dstOffsetBytes the destination offset
+ * @param lengthBytes the number of bytes to copy
+ */
+ void copyTo(long srcOffsetBytes, WritableMemory destination, long dstOffsetBytes, long lengthBytes);
+
+ /**
+ * Writes bytes from a source range of this Memory to the given {@code WritableByteChannel}.
+ * @param offsetBytes the source offset for this Memory
+ * @param lengthBytes the number of bytes to copy
+ * @param out the destination WritableByteChannel
+ * @throws IOException may occur while writing to the WritableByteChannel
+ */
+ void writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out)
+ throws IOException;
}
diff --git a/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java b/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
index 297a95c..3d1bd69 100644
--- a/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
+++ b/src/main/java/org/apache/datasketches/memory/MemoryRequestServer.java
@@ -19,8 +19,6 @@
package org.apache.datasketches.memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
-
/**
* The MemoryRequestServer is a callback interface to provide a means for a direct (off-heap),
* dynamic WritableMemory object to request more memory from the owner of the
diff --git a/src/main/java/org/apache/datasketches/memory/WritableDirectHandle.java b/src/main/java/org/apache/datasketches/memory/WritableDirectHandle.java
index d1f3473..10ae261 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableDirectHandle.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableDirectHandle.java
@@ -28,5 +28,5 @@ package org.apache.datasketches.memory;
* @author Lee Rhodes
* @author Roman Leventov
*/
-public interface WritableDirectHandle extends WritableHandle { }
+public interface WritableDirectHandle extends WritableHandle { }
diff --git a/src/main/java/org/apache/datasketches/memory/WritableHandle.java b/src/main/java/org/apache/datasketches/memory/WritableHandle.java
index 8b2aaa7..5546d5e 100644
--- a/src/main/java/org/apache/datasketches/memory/WritableHandle.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableHandle.java
@@ -19,8 +19,6 @@
package org.apache.datasketches.memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
-
/**
* A Handle for writable direct memory or a memory-mapped, writable file resource.
* Please read Javadocs for {@link Handle}.
@@ -34,6 +32,5 @@ public interface WritableHandle extends Handle {
* Gets a WritableMemory
* @return a WritableMemory
*/
- @Override
- WritableMemory get();
+ WritableMemory getWritable();
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
similarity index 74%
copy from src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
copy to src/main/java/org/apache/datasketches/memory/WritableMemory.java
index 85b8875..9b53b65 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -17,39 +17,17 @@
* under the License.
*/
-package org.apache.datasketches.memory.internal;
-import static org.apache.datasketches.memory.internal.Util.negativeCheck;
-import static org.apache.datasketches.memory.internal.Util.nullCheck;
-import static org.apache.datasketches.memory.internal.Util.zeroCheck;
+package org.apache.datasketches.memory;
import java.io.File;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.DefaultMemoryRequestServer;
-import org.apache.datasketches.memory.Handle;
-import org.apache.datasketches.memory.MemoryRequestServer;
-import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.WritableMapHandle;
-import org.apache.datasketches.memory.WritableDirectHandle;
+import org.apache.datasketches.memory.internal.WritableBuffer;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
-
-/**
- * Provides read and write primitive and primitive array access to any of the four resources
- * mentioned at the package level.
- *
- * @author Roman Leventov
- * @author Lee Rhodes
- */
-public abstract class WritableMemory extends Memory {
-
- //Pass-through ctor
- WritableMemory(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
- final long capacityBytes) {
- super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
- }
+public interface WritableMemory extends Memory {
//BYTE BUFFER
/**
@@ -63,10 +41,10 @@ public abstract class WritableMemory extends Memory {
* @param byteBuf the given ByteBuffer
* @return a new WritableMemory for write operations on the given ByteBuffer.
*/
- public static WritableMemory writableWrap(final ByteBuffer byteBuf) {
- return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteBuf.order());
+ static WritableMemory writableWrap(final ByteBuffer byteBuf) {
+ return WritableMemoryImpl.writableWrap(byteBuf);
}
-
+
/**
* Accesses the given ByteBuffer for write operations. The returned WritableMemory object has
* the given byte order, ignoring the byte order of the given ByteBuffer. If the capacity of
@@ -80,10 +58,10 @@ public abstract class WritableMemory extends Memory {
* state of the given ByteBuffer
* @return a new WritableMemory for write operations on the given ByteBuffer.
*/
- public static WritableMemory writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
- return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteOrder);
+ static WritableMemory writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ return WritableMemoryImpl.writableWrap(byteBuf, byteOrder);
}
-
+
//MAP
/**
* Maps the entire given file into native-ordered WritableMemory for write operations
@@ -95,12 +73,11 @@ public abstract class WritableMemory extends Memory {
* @param file the given file to map
* @return WritableMapHandle for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
- * @throws IOException file not found or a RuntimeException.
*/
- public static WritableMapHandle writableMap(final File file) throws IOException {
- return WritableMemory.writableMap(file, 0, file.length(), Util.nativeByteOrder);
+ static WritableMapHandle writableMap(final File file) {
+ return WritableMemoryImpl.writableMap(file);
}
-
+
/**
* Maps the specified portion of the given file into Memory for write operations
* (including those > 2GB).
@@ -111,19 +88,14 @@ public abstract class WritableMemory extends Memory {
* @param fileOffsetBytes the position in the given file in bytes. It may not be negative.
* @param capacityBytes the size of the mapped Memory. It may not be negative or zero.
* @param byteOrder the byte order to be used for the given file. It may not be null.
- * @return WritableMapHandleImpl for managing the mapped Memory.
+ * @return WritableMapHandle for managing the mapped Memory.
* Please read Javadocs for {@link Handle}.
- * @throws IOException file not found or RuntimeException, etc.
- */
- public static WritableMapHandle writableMap(final File file, final long fileOffsetBytes,
- final long capacityBytes, final ByteOrder byteOrder) throws IOException {
- zeroCheck(capacityBytes, "Capacity");
- nullCheck(file, "file is null");
- negativeCheck(fileOffsetBytes, "File offset is negative");
- return BaseWritableMemoryImpl
- .wrapMap(file, fileOffsetBytes, capacityBytes, false, byteOrder);
+ */
+ static WritableMapHandle writableMap(final File file, final long fileOffsetBytes,
+ final long capacityBytes, final ByteOrder byteOrder) {
+ return WritableMemoryImpl.writableMap(file, fileOffsetBytes, capacityBytes, byteOrder);
}
-
+
//ALLOCATE DIRECT
/**
* Allocates and provides access to capacityBytes directly in native (off-heap) memory
@@ -140,13 +112,13 @@ public abstract class WritableMemory extends Memory {
* and to call <i>close()</i> when done.</p>
*
* @param capacityBytes the size of the desired memory in bytes.
- * @return WritableDirectHandleImpl for this off-heap resource.
+ * @return WritableDirectHandle for this off-heap resource.
* Please read Javadocs for {@link Handle}.
*/
- public static WritableDirectHandle allocateDirect(final long capacityBytes) {
- return allocateDirect(capacityBytes, null);
+ static WritableDirectHandle allocateDirect(final long capacityBytes) {
+ return WritableMemoryImpl.allocateDirect(capacityBytes);
}
-
+
/**
* Allocates and provides access to capacityBytes directly in native (off-heap) memory
* leveraging the WritableMemory API. The allocated memory will be 8-byte aligned, but may not
@@ -163,11 +135,10 @@ public abstract class WritableMemory extends Memory {
* @return WritableHandle for this off-heap resource.
* Please read Javadocs for {@link Handle}.
*/
- public static WritableDirectHandle allocateDirect(final long capacityBytes,
- final MemoryRequestServer memReqSvr) {
- return BaseWritableMemoryImpl.wrapDirect(capacityBytes, Util.nativeByteOrder, memReqSvr);
+ static WritableDirectHandle allocateDirect(final long capacityBytes, final MemoryRequestServer memReqSvr) {
+ return WritableMemoryImpl.allocateDirect(capacityBytes, memReqSvr);
}
-
+
//REGIONS
/**
* A writable region is a writable view of this object.
@@ -184,7 +155,7 @@ public abstract class WritableMemory extends Memory {
* @param capacityBytes the capacity of the returned object in bytes.
* @return a new <i>WritableMemory</i> representing the defined writable region.
*/
- public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes);
+ WritableMemory writableRegion(long offsetBytes, long capacityBytes);
/**
* A writable region is a writable view of this object.
@@ -203,8 +174,7 @@ public abstract class WritableMemory extends Memory {
* @param byteOrder the given byte order
* @return a new <i>WritableMemory</i> representing the defined writable region.
*/
- public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes,
- ByteOrder byteOrder);
+ WritableMemory writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
//AS BUFFER
/**
@@ -221,7 +191,7 @@ public abstract class WritableMemory extends Memory {
* the backing storage and byte order are unspecified.
* @return a new <i>WritableBuffer</i> with a view of this WritableMemory
*/
- public abstract WritableBuffer asWritableBuffer();
+ WritableBuffer asWritableBuffer();
/**
* Returns a new <i>WritableBuffer</i> with a writable view of this object
@@ -239,8 +209,9 @@ public abstract class WritableMemory extends Memory {
* @param byteOrder the given byte order
* @return a new <i>WritableBuffer</i> with a view of this WritableMemory
*/
- public abstract WritableBuffer asWritableBuffer(ByteOrder byteOrder);
+ WritableBuffer asWritableBuffer(ByteOrder byteOrder);
+
//ALLOCATE HEAP VIA AUTOMATIC BYTE ARRAY
/**
* Creates on-heap WritableMemory with the given capacity and the native byte order. If the given
@@ -249,9 +220,8 @@ public abstract class WritableMemory extends Memory {
* @param capacityBytes the given capacity in bytes.
* @return a new WritableMemory for write operations on a new byte array.
*/
- public static WritableMemory allocate(final int capacityBytes) {
- final byte[] arr = new byte[capacityBytes];
- return writableWrap(arr, Util.nativeByteOrder);
+ static WritableMemory allocate(final int capacityBytes) {
+ return WritableMemoryImpl.allocate(capacityBytes);
}
/**
@@ -262,9 +232,8 @@ public abstract class WritableMemory extends Memory {
* @param byteOrder the given byte order to allocate new Memory object with.
* @return a new WritableMemory for write operations on a new byte array.
*/
- public static WritableMemory allocate(final int capacityBytes, final ByteOrder byteOrder) {
- final byte[] arr = new byte[capacityBytes];
- return writableWrap(arr, byteOrder);
+ static WritableMemory allocate(final int capacityBytes, final ByteOrder byteOrder) {
+ return WritableMemoryImpl.allocate(capacityBytes, byteOrder);
}
//ACCESS PRIMITIVE HEAP ARRAYS for write
@@ -278,9 +247,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final boolean[] arr) {
- final long lengthBytes = arr.length << Prim.BOOLEAN.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final boolean[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -293,8 +261,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final byte[] arr) {
- return WritableMemory.writableWrap(arr, 0, arr.length, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final byte[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -308,8 +276,8 @@ public abstract class WritableMemory extends Memory {
* @param byteOrder the byte order to be used
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final byte[] arr, final ByteOrder byteOrder) {
- return WritableMemory.writableWrap(arr, 0, arr.length, byteOrder);
+ static WritableMemory writableWrap(final byte[] arr, final ByteOrder byteOrder) {
+ return WritableMemoryImpl.writableWrap(arr, byteOrder);
}
/**
@@ -325,10 +293,9 @@ public abstract class WritableMemory extends Memory {
* @param byteOrder the byte order to be used
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
+ static WritableMemory writableWrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
final ByteOrder byteOrder) {
- UnsafeUtil.checkBounds(offsetBytes, lengthBytes, arr.length);
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, byteOrder);
+ return WritableMemoryImpl.writableWrap(arr, offsetBytes, lengthBytes, byteOrder);
}
/**
@@ -341,9 +308,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final char[] arr) {
- final long lengthBytes = arr.length << Prim.CHAR.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final char[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -356,9 +322,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final short[] arr) {
- final long lengthBytes = arr.length << Prim.SHORT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final short[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -371,9 +336,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final int[] arr) {
- final long lengthBytes = arr.length << Prim.INT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final int[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -386,9 +350,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final long[] arr) {
- final long lengthBytes = arr.length << Prim.LONG.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final long[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -401,9 +364,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final float[] arr) {
- final long lengthBytes = arr.length << Prim.FLOAT.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final float[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
/**
@@ -416,9 +378,8 @@ public abstract class WritableMemory extends Memory {
* @param arr the given primitive array.
* @return a new WritableMemory for write operations on the given primitive array.
*/
- public static WritableMemory writableWrap(final double[] arr) {
- final long lengthBytes = arr.length << Prim.DOUBLE.shift();
- return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
+ static WritableMemory writableWrap(final double[] arr) {
+ return WritableMemoryImpl.writableWrap(arr);
}
//END OF CONSTRUCTOR-TYPE METHODS
@@ -428,7 +389,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putBoolean(long offsetBytes, boolean value);
+ void putBoolean(long offsetBytes, boolean value);
/**
* Puts the boolean array at the given offset
@@ -437,7 +398,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetBooleans offset in array units
* @param lengthBooleans number of array units to transfer
*/
- public abstract void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans,
+ void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans,
int lengthBooleans);
/**
@@ -445,7 +406,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putByte(long offsetBytes, byte value);
+ void putByte(long offsetBytes, byte value);
/**
* Puts the byte array at the given offset
@@ -454,7 +415,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetBytes offset in array units
* @param lengthBytes number of array units to transfer
*/
- public abstract void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes,
+ void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes,
int lengthBytes);
/**
@@ -462,7 +423,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putChar(long offsetBytes, char value);
+ void putChar(long offsetBytes, char value);
/**
* Puts the char array at the given offset
@@ -471,7 +432,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetChars offset in array units
* @param lengthChars number of array units to transfer
*/
- public abstract void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars,
+ void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars,
int lengthChars);
/**
@@ -486,14 +447,14 @@ public abstract class WritableMemory extends Memory {
* require 2, 3 or 4 bytes per character to encode.
* @return the number of bytes encoded
*/
- public abstract long putCharsToUtf8(long offsetBytes, CharSequence src);
+ long putCharsToUtf8(long offsetBytes, CharSequence src);
/**
* Puts the double value at the given offset
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putDouble(long offsetBytes, double value);
+ void putDouble(long offsetBytes, double value);
/**
* Puts the double array at the given offset
@@ -502,7 +463,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetDoubles offset in array units
* @param lengthDoubles number of array units to transfer
*/
- public abstract void putDoubleArray(long offsetBytes, double[] srcArray,
+ void putDoubleArray(long offsetBytes, double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles);
/**
@@ -510,7 +471,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putFloat(long offsetBytes, float value);
+ void putFloat(long offsetBytes, float value);
/**
* Puts the float array at the given offset
@@ -519,7 +480,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetFloats offset in array units
* @param lengthFloats number of array units to transfer
*/
- public abstract void putFloatArray(long offsetBytes, float[] srcArray,
+ void putFloatArray(long offsetBytes, float[] srcArray,
final int srcOffsetFloats, final int lengthFloats);
/**
@@ -527,7 +488,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putInt(long offsetBytes, int value);
+ void putInt(long offsetBytes, int value);
/**
* Puts the int array at the given offset
@@ -536,7 +497,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetInts offset in array units
* @param lengthInts number of array units to transfer
*/
- public abstract void putIntArray(long offsetBytes, int[] srcArray,
+ void putIntArray(long offsetBytes, int[] srcArray,
final int srcOffsetInts, final int lengthInts);
/**
@@ -544,7 +505,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putLong(long offsetBytes, long value);
+ void putLong(long offsetBytes, long value);
/**
* Puts the long array at the given offset
@@ -553,7 +514,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetLongs offset in array units
* @param lengthLongs number of array units to transfer
*/
- public abstract void putLongArray(long offsetBytes, long[] srcArray,
+ void putLongArray(long offsetBytes, long[] srcArray,
final int srcOffsetLongs, final int lengthLongs);
/**
@@ -561,7 +522,7 @@ public abstract class WritableMemory extends Memory {
* @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
* @param value the value to put
*/
- public abstract void putShort(long offsetBytes, short value);
+ void putShort(long offsetBytes, short value);
/**
* Puts the short array at the given offset
@@ -570,7 +531,7 @@ public abstract class WritableMemory extends Memory {
* @param srcOffsetShorts offset in array units
* @param lengthShorts number of array units to transfer
*/
- public abstract void putShortArray(long offsetBytes, short[] srcArray,
+ void putShortArray(long offsetBytes, short[] srcArray,
final int srcOffsetShorts, final int lengthShorts);
//Atomic Methods
@@ -580,7 +541,7 @@ public abstract class WritableMemory extends Memory {
* @param delta the amount to add
* @return the the previous value
*/
- public abstract long getAndAddLong(long offsetBytes, long delta);
+ long getAndAddLong(long offsetBytes, long delta);
/**
* Atomically sets the current value at the memory location to the given updated value
@@ -591,7 +552,7 @@ public abstract class WritableMemory extends Memory {
* @return {@code true} if successful. False return indicates that
* the current value at the memory location was not equal to the expected value.
*/
- public abstract boolean compareAndSwapLong(long offsetBytes, long expect, long update);
+ boolean compareAndSwapLong(long offsetBytes, long expect, long update);
/**
* Atomically exchanges the given value with the current value located at offsetBytes.
@@ -599,39 +560,39 @@ public abstract class WritableMemory extends Memory {
* @param newValue new value
* @return the previous value
*/
- public abstract long getAndSetLong(long offsetBytes, long newValue);
+ long getAndSetLong(long offsetBytes, long newValue);
//OTHER WRITE METHODS
/**
* Returns the primitive backing array, otherwise null.
* @return the primitive backing array, otherwise null.
*/
- public abstract Object getArray();
+ Object getArray();
/**
* Clears all bytes of this Memory to zero
*/
- public abstract void clear();
+ void clear();
/**
* Clears a portion of this Memory to zero.
* @param offsetBytes offset bytes relative to this Memory start
* @param lengthBytes the length in bytes
*/
- public abstract void clear(long offsetBytes, long lengthBytes);
+ void clear(long offsetBytes, long lengthBytes);
/**
* Clears the bits defined by the bitMask
* @param offsetBytes offset bytes relative to this Memory start.
* @param bitMask the bits set to one will be cleared
*/
- public abstract void clearBits(long offsetBytes, byte bitMask);
+ void clearBits(long offsetBytes, byte bitMask);
/**
* Fills all bytes of this Memory region to the given byte value.
* @param value the given byte value
*/
- public abstract void fill(byte value);
+ void fill(byte value);
/**
* Fills a portion of this Memory region to the given byte value.
@@ -639,14 +600,14 @@ public abstract class WritableMemory extends Memory {
* @param lengthBytes the length in bytes
* @param value the given byte value
*/
- public abstract void fill(long offsetBytes, long lengthBytes, byte value);
+ void fill(long offsetBytes, long lengthBytes, byte value);
/**
* Sets the bits defined by the bitMask
* @param offsetBytes offset bytes relative to this Memory start
* @param bitMask the bits set to one will be set
*/
- public abstract void setBits(long offsetBytes, byte bitMask);
+ void setBits(long offsetBytes, byte bitMask);
//OTHER WRITABLE API METHODS
@@ -658,9 +619,14 @@ public abstract class WritableMemory extends Memory {
* If not explicity set, this returns the {@link DefaultMemoryRequestServer}.
* @return the MemoryRequestServer object (if direct memory) or null.
*/
- @Override
- public MemoryRequestServer getMemoryRequestServer() {
- return null;
- }
+ MemoryRequestServer getMemoryRequestServer();
+
+
+
+
+
+
}
+
+
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
index aef0b98..bc47f57 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java
@@ -44,7 +44,7 @@ final class AllocateDirect implements AutoCloseable {
* Base Constructor for allocate native memory.
*
* <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory
- * leveraging the Memory interface.
+ * leveraging the MemoryImpl interface.
* The allocated memory will be 8-byte aligned, but may not be page aligned.
* @param capacityBytes the the requested capacity of off-heap memory. Cannot be zero.
*/
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
index b5528a5..de0dde0 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
@@ -122,6 +122,8 @@ class AllocateDirectMap implements Map {
cleaner = Cleaner.create(this, deallocator);
}
+ //Map Interface
+
@Override
public void load() {
madvise();
@@ -150,7 +152,8 @@ class AllocateDirectMap implements Map {
String.format("Encountered %s exception while loading", e.getClass()));
}
}
-
+ // End Map Interface
+
@Override
public void close() {
doClose();
diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
index 0d7d609..8a64a27 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMap.java
@@ -31,7 +31,7 @@ import org.apache.datasketches.memory.WritableMap;
* @author Roman Leventov
* @author Praveenkumar Venkatesan
*/
-//Called from WritableMemory, implements combo of WritableMemory with WritableMap resource
+//Called from WritableMemoryImpl, implements combo of WritableMemoryImpl with WritableMap resource
final class AllocateDirectWritableMap extends AllocateDirectMap implements WritableMap {
AllocateDirectWritableMap(final File file, final long fileOffsetBytes,
@@ -39,10 +39,12 @@ final class AllocateDirectWritableMap extends AllocateDirectMap implements Writa
super(file, fileOffsetBytes, capacityBytes, localReadOnly);
}
+ //Added by WritableMap Interface
+
@Override
public void force() {
if (resourceReadOnly) {
- throw new ReadOnlyException("Memory Mapped File is Read Only.");
+ throw new ReadOnlyException("MemoryImpl Mapped File is Read Only.");
}
try {
MAPPED_BYTE_BUFFER_FORCE0_METHOD
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
index 3c1c3e7..ff3f3c5 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
@@ -23,7 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for ByteBuffer, non-native byte order.
+ * Implementation of {@link WritableMemoryImpl} for ByteBuffer, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
index 364bc8e..4a9e4ca 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
@@ -23,12 +23,12 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for ByteBuffer, native byte order.
+ * Implementation of {@link WritableMemoryImpl} for ByteBuffer, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class BBWritableMemoryImpl extends WritableMemoryImpl {
+final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
private static final int id = MEMORY | NATIVE | BYTEBUF;
private final Object unsafeObj;
private final long nativeBaseOffset; //used to compute cumBaseOffset
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 caa3e99..8855c99 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -33,7 +33,7 @@ import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.BaseState;
/**
- * Keeps key configuration state for Memory and Buffer plus some common static variables
+ * Keeps key configuration state for MemoryImpl and Buffer plus some common static variables
* and check methods.
*
* @author Lee Rhodes
@@ -73,8 +73,8 @@ public abstract class BaseStateImpl implements BaseState {
/**
* This becomes the base offset used by all Unsafe calls. It is cumulative in that in includes
- * all offsets from regions, user-defined offsets when creating Memory, and the array object
- * header offset when creating Memory from primitive arrays.
+ * all offsets from regions, user-defined offsets when creating MemoryImpl, and the array object
+ * header offset when creating MemoryImpl from primitive arrays.
*/
private final long cumBaseOffset_;
@@ -162,7 +162,7 @@ public abstract class BaseStateImpl implements BaseState {
return cumBaseOffset_ + offsetBytes;
}
- //made public in WritableMemory and WritableBuffer, only implemented in Direct Leafs
+ //made public in WritableMemoryImpl and WritableBuffer, only implemented in Direct Leafs
abstract MemoryRequestServer getMemoryRequestServer();
//Overridden by ByteBuffer, Direct and Map leafs
@@ -186,7 +186,7 @@ public abstract class BaseStateImpl implements BaseState {
//Overridden by all leafs
abstract int getTypeId();
- //Overridden by Heap and ByteBuffer Leafs. Made public as getArray() in WritableMemory and
+ //Overridden by Heap and ByteBuffer Leafs. Made public as getArray() in WritableMemoryImpl and
// WritableBuffer
Object getUnsafeObject() {
return null;
@@ -248,12 +248,12 @@ public abstract class BaseStateImpl implements BaseState {
//ASSERTS AND CHECKS
final void assertValid() {
- assert isValid() : "Memory not valid.";
+ assert isValid() : "MemoryImpl not valid.";
}
void checkValid() {
if (!isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
@@ -271,7 +271,7 @@ public abstract class BaseStateImpl implements BaseState {
// because the later can make JVM to not inline the assert code path (and entirely remove it)
// even though it does nothing in production code path.
assertBounds(offsetBytes, lengthBytes, capacityBytes_);
- assert !isReadOnly() : "Memory is read-only.";
+ assert !isReadOnly() : "MemoryImpl is read-only.";
}
@Override
@@ -286,7 +286,7 @@ public abstract class BaseStateImpl implements BaseState {
//read capacityBytes_ directly to eliminate extra checkValid() call
checkBounds(offsetBytes, lengthBytes, capacityBytes_);
if (isReadOnly()) {
- throw new ReadOnlyException("Memory is read-only.");
+ throw new ReadOnlyException("MemoryImpl is read-only.");
}
}
@@ -386,7 +386,7 @@ public abstract class BaseStateImpl implements BaseState {
* Used primarily for testing.
* @param state the BaseStateImpl
* @param preamble a descriptive header
- * @param offsetBytes offset bytes relative to the Memory start
+ * @param offsetBytes offset bytes relative to the MemoryImpl start
* @param lengthBytes number of bytes to convert to a hex string
* @return a formatted hex string in a human readable array
*/
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 0402e0a..935b364 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -147,14 +147,14 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
//MEMORY
@Override
- public Memory asMemory() {
+ public MemoryImpl asMemory() {
return originMemory;
}
@Override
- public WritableMemory asWritableMemory() {
+ public WritableMemoryImpl asWritableMemory() {
if (isReadOnly()) {
- throw new ReadOnlyException("Converting a read-only Buffer to a writable Memory is not allowed.");
+ throw new ReadOnlyException("Converting a read-only Buffer to a writable MemoryImpl is not allowed.");
}
return originMemory;
}
@@ -271,7 +271,7 @@ abstract class BaseWritableBufferImpl extends WritableBuffer {
/*
* Develper notes: There is no copyTo for Buffers because of the ambiguity of what to do with
- * the positional values. Switch to Memory view to do copyTo.
+ * the positional values. Switch to MemoryImpl view to do copyTo.
*/
//PRIMITIVE putX() and putXArray()
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 f7aba4e..872cc05 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -36,8 +36,10 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;
+import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMapHandle;
+import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.memory.WritableDirectHandle;
/*
@@ -53,11 +55,11 @@ import org.apache.datasketches.memory.WritableDirectHandle;
*/
/**
- * Common base of native-ordered and non-native-ordered {@link WritableMemory} implementations.
+ * Common base of native-ordered and non-native-ordered {@link WritableMemoryImpl} implementations.
* Contains methods which are agnostic to the byte order.
*/
@SuppressWarnings({"restriction"})
-abstract class BaseWritableMemoryImpl extends WritableMemory {
+abstract class BaseWritableMemoryImpl extends WritableMemoryImpl {
//1KB of empty bytes for speedy clear()
private final static byte[] EMPTY_BYTES;
@@ -152,7 +154,7 @@ abstract class BaseWritableMemoryImpl extends WritableMemory {
.slice().asReadOnlyBuffer();
} else {
throw new UnsupportedOperationException(
- "This Memory object is the result of wrapping a "
+ "This MemoryImpl object is the result of wrapping a "
+ unsafeObj.getClass().getSimpleName()
+ " array, it could not be viewed as a ByteBuffer.");
}
@@ -162,31 +164,31 @@ abstract class BaseWritableMemoryImpl extends WritableMemory {
//REGIONS
@Override
- public Memory region(final long offsetBytes, final long capacityBytes) {
+ public MemoryImpl region(final long offsetBytes, final long capacityBytes) {
return writableRegionImpl(offsetBytes, capacityBytes, true, getTypeByteOrder());
}
@Override
- public Memory region(final long offsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
+ public MemoryImpl region(final long offsetBytes, final long capacityBytes, final ByteOrder byteOrder) {
return writableRegionImpl(offsetBytes, capacityBytes, true, byteOrder);
}
@Override
- public WritableMemory writableRegion(final long offsetBytes, final long capacityBytes) {
+ public WritableMemoryImpl writableRegion(final long offsetBytes, final long capacityBytes) {
return writableRegionImpl(offsetBytes, capacityBytes, false, getTypeByteOrder());
}
@Override
- public WritableMemory writableRegion(final long offsetBytes, final long capacityBytes,
+ public WritableMemoryImpl writableRegion(final long offsetBytes, final long capacityBytes,
final ByteOrder byteOrder) {
return writableRegionImpl(offsetBytes, capacityBytes, false, byteOrder);
}
- WritableMemory writableRegionImpl(final long offsetBytes, final long capacityBytes,
+ WritableMemoryImpl writableRegionImpl(final long offsetBytes, final long capacityBytes,
final boolean localReadOnly, final ByteOrder byteOrder) {
if (capacityBytes == 0) { return ZERO_SIZE_MEMORY; }
if (isReadOnly() && !localReadOnly) {
- throw new ReadOnlyException("Writable region of a read-only Memory is not allowed.");
+ throw new ReadOnlyException("Writable region of a read-only MemoryImpl is not allowed.");
}
final boolean readOnly = isReadOnly() || localReadOnly;
checkValidAndBounds(offsetBytes, capacityBytes);
@@ -220,7 +222,7 @@ abstract class BaseWritableMemoryImpl extends WritableMemory {
WritableBuffer asWritableBufferImpl(final boolean localReadOnly, final ByteOrder byteOrder) {
if (isReadOnly() && !localReadOnly) {
throw new ReadOnlyException(
- "Converting a read-only Memory to a writable Buffer is not allowed.");
+ "Converting a read-only MemoryImpl to a writable Buffer is not allowed.");
}
final boolean readOnly = isReadOnly() || localReadOnly;
final WritableBuffer wbuf = toWritableBuffer(readOnly, byteOrder);
@@ -316,14 +318,14 @@ abstract class BaseWritableMemoryImpl extends WritableMemory {
@Override
public final int compareTo(final long thisOffsetBytes, final long thisLengthBytes,
final Memory thatMem, final long thatOffsetBytes, final long thatLengthBytes) {
- return CompareAndCopy.compare(this, thisOffsetBytes, thisLengthBytes,
- thatMem, thatOffsetBytes, thatLengthBytes);
+ return CompareAndCopy.compare((BaseStateImpl)this, thisOffsetBytes, thisLengthBytes,
+ (BaseStateImpl)thatMem, thatOffsetBytes, thatLengthBytes);
}
@Override
public final void copyTo(final long srcOffsetBytes, final WritableMemory destination,
final long dstOffsetBytes, final long lengthBytes) {
- CompareAndCopy.copy(this, srcOffsetBytes, destination,
+ CompareAndCopy.copy((BaseStateImpl)this, srcOffsetBytes, (BaseStateImpl)destination,
dstOffsetBytes, lengthBytes);
}
@@ -336,7 +338,7 @@ abstract class BaseWritableMemoryImpl extends WritableMemory {
} else if (getUnsafeObject() == null) {
writeDirectMemoryTo(offsetBytes, lengthBytes, out);
} else {
- // Memory is backed by some array that is not byte[], for example int[], long[], etc.
+ // MemoryImpl is backed by some array that is not byte[], for example int[], long[], etc.
// We don't have other choice as to do extra intermediate copy.
writeToWithExtraCopy(offsetBytes, lengthBytes, out);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Buffer.java b/src/main/java/org/apache/datasketches/memory/internal/Buffer.java
index 5380e56..824a4a5 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Buffer.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/Buffer.java
@@ -70,7 +70,7 @@ public abstract class Buffer extends BaseBuffer {
}
//MAP
- //Use Memory for mapping files and the asBuffer()
+ //Use MemoryImpl for mapping files and the asBuffer()
//DUPLICATES
/**
@@ -146,8 +146,8 @@ public abstract class Buffer extends BaseBuffer {
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing storage and byte order are unspecified.
*
- * <p><b>Note: The Memory returned with </b><i>asMemory()</i> will have the originating
- * <i>Memory</i> byte order.</p>
+ * <p><b>Note: The MemoryImpl returned with </b><i>asMemory()</i> will have the originating
+ * <i>MemoryImpl</i> byte order.</p>
*
* @param offsetBytes the starting offset with respect to the origin of this <i>WritableBuffer</i>
* @param capacityBytes the <i>capacity</i> of the returned region in bytes
@@ -160,16 +160,16 @@ public abstract class Buffer extends BaseBuffer {
//MEMORY
/**
- * Convert this Buffer to a Memory. The current <i>start</i>, <i>position</i> and <i>end</i>
+ * Convert this Buffer to a MemoryImpl. The current <i>start</i>, <i>position</i> and <i>end</i>
* are ignored.
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing resource and byte order are unspecified.
- * @return Memory
+ * @return MemoryImpl
*/
- public abstract Memory asMemory();
+ public abstract MemoryImpl asMemory();
//ACCESS PRIMITIVE HEAP ARRAYS for readOnly
- // use Memory or WritableMemory and then asBuffer().
+ // use MemoryImpl or WritableMemoryImpl and then asBuffer().
//END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE getX() and getXArray()
@@ -183,7 +183,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the boolean value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the boolean at the given offset
*/
public abstract boolean getBoolean(long offsetBytes);
@@ -208,7 +208,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the byte value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the byte at the given offset
*/
public abstract byte getByte(long offsetBytes);
@@ -232,7 +232,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the char value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the char at the given offset
*/
public abstract char getChar(long offsetBytes);
@@ -256,7 +256,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the double value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the double at the given offset
*/
public abstract double getDouble(long offsetBytes);
@@ -280,7 +280,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the float value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the float at the given offset
*/
public abstract float getFloat(long offsetBytes);
@@ -304,7 +304,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the int value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the int at the given offset
*/
public abstract int getInt(long offsetBytes);
@@ -328,7 +328,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the long value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the long at the given offset
*/
public abstract long getLong(long offsetBytes);
@@ -352,7 +352,7 @@ public abstract class Buffer extends BaseBuffer {
/**
* Gets the short value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this Memory start
+ * @param offsetBytes offset bytes relative to this MemoryImpl start
* @return the short at the given offset
*/
public abstract short getShort(long offsetBytes);
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 0baf90a..089e576 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java
@@ -124,7 +124,7 @@ final class CompareAndCopy {
lengthBytes);
}
- //Used by all of the get/put array methods in Buffer and Memory classes
+ //Used by all of the get/put array methods in Buffer and MemoryImpl classes
static final void copyMemoryCheckingDifferentObject(final Object srcUnsafeObj,
final long srcAdd, final Object dstUnsafeObj, final long dstAdd, final long lengthBytes) {
if (srcUnsafeObj != dstUnsafeObj) {
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
index 6d8f159..4358d6b 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
@@ -101,7 +101,7 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
index e8f5a64..9c0ee47 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
@@ -24,7 +24,7 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.MemoryRequestServer;
/**
- * Implementation of {@link WritableMemory} for direct memory, non-native byte order.
+ * Implementation of {@link WritableMemoryImpl} for direct memory, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
@@ -99,7 +99,7 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
index c6cd0e6..9b1a287 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
@@ -101,7 +101,7 @@ final class DirectWritableBufferImpl extends WritableBufferImpl {
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
index 21eb03c..9fbb834 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
@@ -24,12 +24,12 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.MemoryRequestServer;
/**
- * Implementation of {@link WritableMemory} for direct memory, native byte order.
+ * Implementation of {@link WritableMemoryImpl} for direct memory, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class DirectWritableMemoryImpl extends WritableMemoryImpl {
+final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
private static final int id = MEMORY | NATIVE | DIRECT;
private final long nativeBaseOffset; //used to compute cumBaseOffset
private final StepBoolean valid; //a reference only
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
index 89d223b..04b3033 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for heap-based, non-native byte order.
+ * Implementation of {@link WritableMemoryImpl} for heap-based, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
diff --git a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
index ead8a7b..4aa398a 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
@@ -22,12 +22,12 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for heap-based, native byte order.
+ * Implementation of {@link WritableMemoryImpl} for heap-based, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class HeapWritableMemoryImpl extends WritableMemoryImpl {
+final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
private static final int id = MEMORY | NATIVE | HEAP;
private final Object unsafeObj;
private final byte typeId;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
index e9741b8..a6bf6fa 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapHandleImpl.java
@@ -20,14 +20,12 @@
package org.apache.datasketches.memory.internal;
import org.apache.datasketches.memory.MapHandle;
+import org.apache.datasketches.memory.Memory;
class MapHandleImpl implements MapHandle {
- /**
- * Having at least one final field makes this class safe for concurrent publication.
- */
final AllocateDirectMap dirMap;
- private BaseWritableMemoryImpl wMem;
+ BaseWritableMemoryImpl wMem;
MapHandleImpl(final AllocateDirectMap dirMap, final BaseWritableMemoryImpl wMem) {
this.dirMap = dirMap;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
index 28e1e98..59ca32d 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
@@ -89,7 +89,7 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
index 9d9e42d..9920c2d 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
@@ -22,7 +22,7 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for map memory, non-native byte order.
+ * Implementation of {@link WritableMemoryImpl} for map memory, non-native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
@@ -88,7 +88,7 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
index cde1289..4a9be74 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
@@ -89,7 +89,7 @@ final class MapWritableBufferImpl extends WritableBufferImpl {
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
index 839c23f..5c9377a 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
@@ -22,12 +22,12 @@ package org.apache.datasketches.memory.internal;
import java.nio.ByteOrder;
/**
- * Implementation of {@link WritableMemory} for map memory, native byte order.
+ * Implementation of {@link WritableMemoryImpl} for map memory, native byte order.
*
* @author Roman Leventov
* @author Lee Rhodes
*/
-final class MapWritableMemoryImpl extends WritableMemoryImpl {
+final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
private static final int id = MEMORY | NATIVE | MAP;
private final long nativeBaseOffset; //used to compute cumBaseOffset
private final StepBoolean valid; //a reference only
@@ -88,7 +88,7 @@ final class MapWritableMemoryImpl extends WritableMemoryImpl {
@Override
void checkValid() {
if (!this.isValid()) {
- throw new IllegalStateException("Memory not valid.");
+ throw new IllegalStateException("MemoryImpl not valid.");
}
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
index 25fbdbb..4761ec6 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/MemoryImpl.java
@@ -29,8 +29,9 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;
-import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.MapHandle;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableMemory;
/**
* Provides read-only primitive and primitive array methods to any of the four resources
@@ -41,81 +42,30 @@ import org.apache.datasketches.memory.MapHandle;
*
* @see org.apache.datasketches.memory.internal
*/
-public abstract class Memory extends BaseStateImpl {
+public abstract class MemoryImpl extends BaseStateImpl implements Memory {
//Pass-through ctor
- Memory(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
+ MemoryImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
final long capacityBytes) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
}
//BYTE BUFFER
- /**
- * Accesses the given ByteBuffer for read-only operations. The returned <i>Memory</i> object has
- * the same byte order, as the given ByteBuffer, unless the capacity of the given ByteBuffer is
- * zero, then byte order of the returned <i>Memory</i> object (as well as backing storage) is
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param byteBuf the given ByteBuffer, must not be null
- * @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
- */
- public static Memory wrap(final ByteBuffer byteBuf) {
+ public static MemoryImpl wrap(final ByteBuffer byteBuf) {
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, true, byteBuf.order());
}
- /**
- * Accesses the given ByteBuffer for read-only operations. The returned <i>Memory</i> object has
- * the given byte order, ignoring the byte order of the given ByteBuffer. If the capacity of the
- * given ByteBuffer is zero the byte order of the returned <i>Memory</i> object (as well as
- * backing storage) is unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param byteBuf the given ByteBuffer, must not be null
- * @param byteOrder the byte order to be used, whicn may be independent of the byte order
- * state of the given ByteBuffer.
- * @return a new <i>Memory</i> for read-only operations on the given ByteBuffer.
- */
- public static Memory wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ public static MemoryImpl wrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, true, byteOrder);
}
//MAP
- /**
- * Maps the entire given file into native-ordered Memory for read operations
- * (including those > 2GB).
- * Calling this method is equivalent to calling {@link #map(File, long, long, ByteOrder)
- * map(file, 0, file.length(), ByteOrder.nativeOrder())}.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.map(...)</i>.
- * @param file the given file to map
- * @return <i>MapHandle</i> for managing the mapped Memory.
- * Please read Javadocs for {@link Handle}.
- * @throws IOException if file not found or a RuntimeException.
- */
- public static MapHandle map(final File file) throws IOException {
+ public static MapHandle map(final File file) {
return map(file, 0, file.length(), ByteOrder.nativeOrder());
}
- /**
- * Maps the specified portion of the given file into Memory for read operations
- * (including those > 2GB).
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.map(...)</i>.
- * @param file the given file to map. It may not be null.
- * @param fileOffsetBytes the position in the given file in bytes. It may not be negative.
- * @param capacityBytes the size of the mapped Memory. It may not be negative or zero.
- * @param byteOrder the byte order to be used for the mapped Memory. It may not be null.
- * @return <i>MapHandle</i> for managing the mapped Memory.
- * Please read Javadocs for {@link Handle}.
- * @throws IOException if file not found or a RuntimeException.
- */
public static MapHandle map(final File file, final long fileOffsetBytes, final long capacityBytes,
- final ByteOrder byteOrder) throws IOException {
+ final ByteOrder byteOrder) {
zeroCheck(capacityBytes, "Capacity");
nullCheck(file, "file is null");
negativeCheck(fileOffsetBytes, "File offset is negative");
@@ -123,465 +73,151 @@ public abstract class Memory extends BaseStateImpl {
}
//REGIONS
- /**
- * A region is a read-only view of this object.
- * <ul>
- * <li>Returned object's origin = this object's origin + offsetBytes</li>
- * <li>Returned object's capacity = capacityBytes</li>
- * </ul>
- * If the given capacityBytes is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @param offsetBytes the starting offset with respect to the origin of this Memory.
- * @param capacityBytes the capacity of the region in bytes
- * @return a new <i>Memory</i> representing the defined region based on the given
- * offsetBytes and capacityBytes.
- */
- public abstract Memory region(long offsetBytes, long capacityBytes);
-
- /**
- * A region is a read-only view of this object.
- * <ul>
- * <li>Returned object's origin = this object's origin + <i>offsetBytes</i></li>
- * <li>Returned object's capacity = <i>capacityBytes</i></li>
- * <li>Returned object's byte order = <i>byteOrder</i></li>
- * </ul>
- * If the given capacityBytes is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @param offsetBytes the starting offset with respect to the origin of this Memory.
- * @param capacityBytes the capacity of the region in bytes
- * @param byteOrder the given byte order
- * @return a new <i>Memory</i> representing the defined region based on the given
- * offsetBytes, capacityBytes and byteOrder.
- */
- public abstract Memory region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
+ @Override
+ public abstract MemoryImpl region(long offsetBytes, long capacityBytes);
+
+ @Override
+ public abstract MemoryImpl region(long offsetBytes, long capacityBytes, ByteOrder byteOrder);
//AS BUFFER
- /**
- * Returns a new <i>Buffer</i> view of this object.
- * <ul>
- * <li>Returned object's origin = this object's origin</li>
- * <li>Returned object's <i>start</i> = 0</li>
- * <li>Returned object's <i>position</i> = 0</li>
- * <li>Returned object's <i>end</i> = this object's capacity</li>
- * <li>Returned object's <i>capacity</i> = this object's capacity</li>
- * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
- * </ul>
- * If this object's capacity is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @return a new <i>Buffer</i>
- */
+ @Override
public abstract Buffer asBuffer();
- /**
- * Returns a new <i>Buffer</i> view of this object, with the given
- * byte order.
- * <ul>
- * <li>Returned object's origin = this object's origin</li>
- * <li>Returned object's <i>start</i> = 0</li>
- * <li>Returned object's <i>position</i> = 0</li>
- * <li>Returned object's <i>end</i> = this object's capacity</li>
- * <li>Returned object's <i>capacity</i> = this object's capacity</li>
- * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
- * </ul>
- * If this object's capacity is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @param byteOrder the given byte order
- * @return a new <i>Buffer</i> with the given byteOrder.
- */
+ @Override
public abstract Buffer asBuffer(ByteOrder byteOrder);
-
//UNSAFE BYTE BUFFER VIEW
- /**
- * Returns the specified region of this Memory object as a new read-only {@link ByteBuffer}
- * object. The {@link ByteOrder} of the returned {@code ByteBuffer} corresponds to the {@linkplain
- * #getTypeByteOrder() byte order of this Memory}. The returned ByteBuffer's position is 0 and
- * the limit is equal to the capacity.
- *
- * <p>If this Memory object is the result of wrapping non-byte Java arrays ({@link
- * Memory#wrap(int[])}, {@link Memory#wrap(long[])}, etc.) this methods throws an {@link
- * UnsupportedOperationException}.
- *
- * <p>The name of this method starts with "unsafe" because if this is a native managed Memory
- * (e. g. obtained via {@link #map(File)} or {@link WritableMemory#allocateDirect(long)})), and
- * the returned {@code ByteBuffer} object is used after the Memory is freed, it may cause a JVM
- * crash. This is also possible for Memory objects themselves with some methods,
- * but Memory's use-after-free is caught as an AssertionError, if assertions are enabled.
- *
- * @param offsetBytes the starting offset with respect to the origin of this Memory
- * @param capacityBytes the capacity of the returned ByteBuffer
- * @return a new read-only {@code ByteBuffer} to access the specified region.
- * @throws UnsupportedOperationException if this method couldn't be viewed as ByteBuffer, because
- * when it wraps a non-byte Java array.
- */
+ @Override
public abstract ByteBuffer unsafeByteBufferView(long offsetBytes, int capacityBytes);
//ACCESS PRIMITIVE HEAP ARRAYS for readOnly
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final boolean[] arr) {
final long lengthBytes = arr.length << Prim.BOOLEAN.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true,
Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final byte[] arr) {
- return Memory.wrap(arr, 0, arr.length, Util.nativeByteOrder);
+ return MemoryImpl.wrap(arr, 0, arr.length, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations with the given byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @param byteOrder the byte order to be used
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final byte[] arr, final ByteOrder byteOrder) {
- return Memory.wrap(arr, 0, arr.length, byteOrder);
+ return MemoryImpl.wrap(arr, 0, arr.length, byteOrder);
}
- /**
- * Wraps the given primitive array for read operations with the given byte order. If the given
- * lengthBytes is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @param offsetBytes the byte offset into the given array
- * @param lengthBytes the number of bytes to include from the given array
- * @param byteOrder the byte order to be used
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
final ByteOrder byteOrder) {
UnsafeUtil.checkBounds(offsetBytes, lengthBytes, arr.length);
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, byteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final char[] arr) {
final long lengthBytes = arr.length << Prim.CHAR.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final short[] arr) {
final long lengthBytes = arr.length << Prim.SHORT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final int[] arr) {
final long lengthBytes = arr.length << Prim.INT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final long[] arr) {
final long lengthBytes = arr.length << Prim.LONG.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final float[] arr) {
final long lengthBytes = arr.length << Prim.FLOAT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for read operations assuming native byte order. If the array
- * size is zero, backing storage and byte order of the returned <i>Memory</i> object are
- * unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>Memory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new <i>Memory</i> for read operations
- */
public static Memory wrap(final double[] arr) {
final long lengthBytes = arr.length << Prim.DOUBLE.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, true, Util.nativeByteOrder);
}
//PRIMITIVE getX() and getXArray()
- /**
- * Gets the boolean value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the boolean at the given offset
- */
+
+ @Override
public abstract boolean getBoolean(long offsetBytes);
- /**
- * Gets the boolean array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
+ @Override
public abstract void getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans,
int lengthBooleans);
- /**
- * Gets the byte value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the byte at the given offset
- */
+ @Override
public abstract byte getByte(long offsetBytes);
- /**
- * Gets the byte array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetBytes offset in array units
- * @param lengthBytes number of array units to transfer
- */
+ @Override
public abstract void getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes,
int lengthBytes);
- /**
- * Gets the char value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the char at the given offset
- */
+ @Override
public abstract char getChar(long offsetBytes);
- /**
- * Gets the char array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetChars offset in array units
- * @param lengthChars number of array units to transfer
- */
+ @Override
public abstract void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars,
int lengthChars);
- /**
- * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
- * utf8LengthBytes, decodes them into characters and appends them to the given Appendable.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to the Memory start
- * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
- * caller has the correct number of utf8 bytes required to decode the number of characters
- * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
- * character to decode.
- * @param dst the destination Appendable to append the decoded characters to.
- * @return the number of characters decoded
- * @throws IOException if dst.append() throws IOException
- * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
- */
+ @Override
public abstract int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst)
throws IOException, Utf8CodingException;
- /**
- * Gets UTF-8 encoded bytes from this Memory, starting at offsetBytes to a length of
- * utf8LengthBytes, decodes them into characters and appends them to the given StringBuilder.
- * This method does *not* reset the length of the destination StringBuilder before appending
- * characters to it.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to the Memory start
- * @param utf8LengthBytes the number of encoded UTF-8 bytes to decode. It is assumed that the
- * caller has the correct number of utf8 bytes required to decode the number of characters
- * to be appended to dst. Characters outside the ASCII range can require 2, 3 or 4 bytes per
- * character to decode.
- * @param dst the destination StringBuilder to append decoded characters to.
- * @return the number of characters decoded.
- * @throws Utf8CodingException in case of malformed or illegal UTF-8 input
- */
+ @Override
public abstract int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
final StringBuilder dst) throws Utf8CodingException;
- /**
- * Gets the double value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the double at the given offset
- */
+ @Override
public abstract double getDouble(long offsetBytes);
- /**
- * Gets the double array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetDoubles offset in array units
- * @param lengthDoubles number of array units to transfer
- */
+ @Override
public abstract void getDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles,
int lengthDoubles);
- /**
- * Gets the float value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the float at the given offset
- */
+ @Override
public abstract float getFloat(long offsetBytes);
- /**
- * Gets the float array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetFloats offset in array units
- * @param lengthFloats number of array units to transfer
- */
+ @Override
public abstract void getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats,
int lengthFloats);
- /**
- * Gets the int value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the int at the given offset
- */
+ @Override
public abstract int getInt(long offsetBytes);
- /**
- * Gets the int array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetInts offset in array units
- * @param lengthInts number of array units to transfer
- */
+ @Override
public abstract void getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts,
int lengthInts);
- /**
- * Gets the long value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the long at the given offset
- */
+ @Override
public abstract long getLong(long offsetBytes);
- /**
- * Gets the long array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetLongs offset in array units
- * @param lengthLongs number of array units to transfer
- */
+ @Override
public abstract void getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs,
int lengthLongs);
- /**
- * Gets the short value at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @return the short at the given offset
- */
+ @Override
public abstract short getShort(long offsetBytes);
- /**
- * Gets the short array at the given offset
- * @param offsetBytes offset bytes relative to this Memory start
- * @param dstArray The preallocated destination array.
- * @param dstOffsetShorts offset in array units
- * @param lengthShorts number of array units to transfer
- */
+ @Override
public abstract void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts,
int lengthShorts);
//SPECIAL PRIMITIVE READ METHODS: compareTo, copyTo, writeTo
- /**
- * Compares the bytes of this Memory to <i>that</i> Memory.
- * Returns <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
- * : 0;</i>.
- * If all bytes are equal up to the shorter of the two lengths, the shorter length is considered
- * to be less than the other.
- * @param thisOffsetBytes the starting offset for <i>this Memory</i>
- * @param thisLengthBytes the length of the region to compare from <i>this Memory</i>
- * @param that the other Memory to compare with
- * @param thatOffsetBytes the starting offset for <i>that Memory</i>
- * @param thatLengthBytes the length of the region to compare from <i>that Memory</i>
- * @return <i>(this < that) ? (some negative value) : (this > that) ? (some positive value)
- * : 0;</i>
- */
+ @Override
public abstract int compareTo(long thisOffsetBytes, long thisLengthBytes, Memory that,
long thatOffsetBytes, long thatLengthBytes);
- /**
- * Copies bytes from a source range of this Memory to a destination range of the given Memory
- * with the same semantics when copying between overlapping ranges of bytes as method
- * {@link java.lang.System#arraycopy(Object, int, Object, int, int)} has. However, if the source
- * and the destination ranges are exactly the same, this method throws {@link
- * IllegalArgumentException}, because it should never be needed in real-world scenarios and
- * therefore indicates a bug.
- * @param srcOffsetBytes the source offset for this Memory
- * @param destination the destination Memory, which may not be Read-Only.
- * @param dstOffsetBytes the destination offset
- * @param lengthBytes the number of bytes to copy
- */
+ @Override
public abstract void copyTo(long srcOffsetBytes, WritableMemory destination, long dstOffsetBytes,
long lengthBytes);
- /**
- * Writes bytes from a source range of this Memory to the given {@code WritableByteChannel}.
- * @param offsetBytes the source offset for this Memory
- * @param lengthBytes the number of bytes to copy
- * @param out the destination WritableByteChannel
- * @throws IOException may occur while writing to the WritableByteChannel
- */
+
+ @Override
public abstract void writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out)
throws IOException;
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 7c416b0..88723eb 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
@@ -50,16 +50,16 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
*/
/**
- * Implementation of {@link WritableMemory} for native endian byte order. Non-native variant is
+ * Implementation of {@link WritableMemoryImpl} for native endian byte order. Non-native variant is
* {@link NonNativeWritableMemoryImpl}.
* @author Roman Leventov
* @author Lee Rhodes
*/
@SuppressWarnings({"restriction"})
-abstract class WritableMemoryImpl extends BaseWritableMemoryImpl {
+abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
//Pass-through ctor
- WritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
+ NativeWritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
final long regionOffset, final long capacityBytes) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
}
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 440403b..658a1dd 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
@@ -43,8 +43,8 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
*/
/**
- * Implementation of {@link WritableMemory} for non-native endian byte order. Native variant is
- * {@link WritableMemoryImpl}.
+ * Implementation of {@link WritableMemoryImpl} for non-native endian byte order. Native variant is
+ * {@link NativeWritableMemoryImpl}.
* @author Roman Leventov
* @author Lee Rhodes
*/
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Utf8.java b/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
index eb0d978..a8365df 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/Utf8.java
@@ -29,8 +29,8 @@ import java.nio.BufferOverflowException;
import java.nio.CharBuffer;
/**
- * Encoding and decoding implementations of {@link WritableMemory#putCharsToUtf8} and
- * {@link Memory#getCharsFromUtf8}.
+ * Encoding and decoding implementations of {@link WritableMemoryImpl#putCharsToUtf8} and
+ * {@link MemoryImpl#getCharsFromUtf8}.
*
* <p>This is specifically designed to reduce the production of intermediate objects (garbage),
* thus significantly reducing pressure on the JVM Garbage Collector.
@@ -345,7 +345,7 @@ final class Utf8 {
// characters remaining, at least 4 bytes of memory space remaining, and the next 2
// characters must be a valid surrogate pair.
//
- // 2) There is insufficient Memory space to encode the current character from one of the
+ // 2) There is insufficient MemoryImpl space to encode the current character from one of the
// ifs above.
//
// We proceed assuming (1). If the following test fails, we move to an exception.
@@ -379,7 +379,7 @@ final class Utf8 {
}
if (bIdx > (byteLimit - 4)) {
- //4 Memory bytes required to encode a surrogate pair.
+ //4 MemoryImpl bytes required to encode a surrogate pair.
final int remaining = (int) ((bIdx - byteLimit) + 4L);
throw Utf8CodingException.shortUtf8EncodeByteLength(remaining);
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/Utf8CodingException.java b/src/main/java/org/apache/datasketches/memory/internal/Utf8CodingException.java
index 2929d7a..1b2cdde 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Utf8CodingException.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/Utf8CodingException.java
@@ -63,7 +63,7 @@ public final class Utf8CodingException extends RuntimeException {
}
static Utf8CodingException shortUtf8EncodeByteLength(final int remaining) {
- final String s = "Too few Memory bytes to encode a surrogate pair: " + remaining;
+ final String s = "Too few MemoryImpl bytes to encode a surrogate pair: " + remaining;
return new Utf8CodingException(s);
}
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 7a250c7..f44c52d 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -47,7 +47,7 @@ public final class Util {
* threshold, because internally it doesn't have safepoint polls, that may cause long
* "Time To Safe Point" pauses in the application. This has been fixed in JDK 9 (see
* https://bugs.openjdk.java.net/browse/JDK-8149596 and
- * https://bugs.openjdk.java.net/browse/JDK-8141491), but not in JDK 8, so the Memory library
+ * https://bugs.openjdk.java.net/browse/JDK-8141491), but not in JDK 8, so the MemoryImpl library
* should keep having this boilerplate as long as it supports Java 8.
*
* <p>A reference to this can be found in java.nio.Bits.</p>
@@ -84,7 +84,7 @@ public final class Util {
* search algorithm. The range must be sorted method) prior to making this call.
* If it is not sorted, the results are undefined. If the range contains
* multiple elements with the specified value, there is no guarantee which one will be found.
- * @param mem the Memory to be searched
+ * @param mem the MemoryImpl to be searched
* @param fromLongIndex the index of the first element (inclusive) to be searched
* @param toLongIndex the index of the last element (exclusive) to be searched
* @param key the value to be searched for
@@ -94,7 +94,7 @@ public final class Util {
* than the key, or toIndex if all elements in the range are less than the specified key.
* Note that this guarantees that the return value will be ≥ 0 if and only if the key is found.
*/
- public static long binarySearchLongs(final Memory mem, final long fromLongIndex,
+ public static long binarySearchLongs(final MemoryImpl mem, final long fromLongIndex,
final long toLongIndex, final long key) {
checkBounds(fromLongIndex << 3, (toLongIndex - fromLongIndex) << 3, mem.getCapacity());
long low = fromLongIndex;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java b/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java
index d6f5e88..5911ca9 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableBuffer.java
@@ -72,10 +72,10 @@ public abstract class WritableBuffer extends Buffer {
}
//MAP
- //Use WritableMemory for mapping files and then asWritableBuffer()
+ //Use WritableMemoryImpl for mapping files and then asWritableBuffer()
//ALLOCATE DIRECT
- //Use WritableMemory to allocate direct memory and then asWritableBuffer().
+ //Use WritableMemoryImpl to allocate direct memory and then asWritableBuffer().
//DUPLICATES
/**
@@ -152,7 +152,7 @@ public abstract class WritableBuffer extends Buffer {
* the backing storage and byte order are unspecified.
*
* <p><b>Note: </b><i>asWritableMemory()</i> and <i>asMemory()</i>
- * will return the originating <i>Memory</i> byte order.</p>
+ * will return the originating <i>MemoryImpl</i> byte order.</p>
* @param offsetBytes the starting offset with respect to the origin of this <i>WritableBuffer</i>
* @param capacityBytes the <i>capacity</i> of the returned region in bytes
* @param byteOrder the given byte order
@@ -164,15 +164,15 @@ public abstract class WritableBuffer extends Buffer {
//AS MEMORY
/**
- * Convert this WritableBuffer to a WritableMemory.
+ * Convert this WritableBuffer to a WritableMemoryImpl.
* If this object's capacity is zero, the returned object is effectively immutable and
* the backing storage and byte order are unspecified.
- * @return WritableMemory
+ * @return WritableMemoryImpl
*/
- public abstract WritableMemory asWritableMemory();
+ public abstract WritableMemoryImpl asWritableMemory();
//ACCESS PRIMITIVE HEAP ARRAYS for write
- //use WritableMemory and then asWritableBuffer().
+ //use WritableMemoryImpl and then asWritableBuffer().
//END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE putX() and putXArray()
@@ -186,7 +186,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the boolean value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start.
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start.
* @param value the value to put
*/
public abstract void putBoolean(long offsetBytes, boolean value);
@@ -211,7 +211,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the byte value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putByte(long offsetBytes, byte value);
@@ -235,7 +235,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the char value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putChar(long offsetBytes, char value);
@@ -259,7 +259,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the double value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putDouble(long offsetBytes, double value);
@@ -283,7 +283,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the float value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putFloat(long offsetBytes, float value);
@@ -307,7 +307,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the int value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putInt(long offsetBytes, int value);
@@ -331,7 +331,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the long value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putLong(long offsetBytes, long value);
@@ -355,7 +355,7 @@ public abstract class WritableBuffer extends Buffer {
/**
* Puts the short value at the given offset.
* This does not change the position.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
+ * @param offsetBytes offset bytes relative to this <i>WritableMemoryImpl</i> start
* @param value the value to put
*/
public abstract void putShort(long offsetBytes, short value);
@@ -390,10 +390,10 @@ public abstract class WritableBuffer extends Buffer {
//OTHER WRITABLE API METHODS
/**
- * For Direct Memory only. Other types of backing resources will return null.
+ * For Direct MemoryImpl only. Other types of backing resources will return null.
* Gets the MemoryRequestServer object used by dynamic off-heap (Direct) memory objects
* to request additional memory.
- * Set using {@link WritableMemory#allocateDirect(long, MemoryRequestServer)}.
+ * Set using {@link WritableMemoryImpl#allocateDirect(long, MemoryRequestServer)}.
* If not explicity set, this returns the {@link DefaultMemoryRequestServer}.
* @return the MemoryRequestServer object (if direct memory) or null.
*/
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java b/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
index aaedf42..b62a1a0 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableDirectHandleImpl.java
@@ -20,11 +20,13 @@
package org.apache.datasketches.memory.internal;
import org.apache.datasketches.memory.Handle;
+import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableDirectHandle;
+import org.apache.datasketches.memory.WritableMemory;
/**
* A Handle for a writable direct memory resource.
- * Joins a WritableMemory with a writable, AutoCloseable AllocateDirect resource.
+ * Joins a WritableMemoryImpl with a writable, AutoCloseable AllocateDirect resource.
* Please read Javadocs for {@link Handle}.
*
* @author Lee Rhodes
@@ -36,15 +38,20 @@ public final class WritableDirectHandleImpl implements WritableDirectHandle {
* Having at least one final field makes this class safe for concurrent publication.
*/
final AllocateDirect direct;
- private WritableMemory wMem;
+ private BaseWritableMemoryImpl wMem;
- WritableDirectHandleImpl(final AllocateDirect allocatedDirect, final WritableMemory wMem) {
+ WritableDirectHandleImpl(final AllocateDirect allocatedDirect, final BaseWritableMemoryImpl wMem) {
direct = allocatedDirect;
this.wMem = wMem;
}
@Override
- public WritableMemory get() {
+ public Memory get() {
+ return wMem;
+ }
+
+ @Override
+ public WritableMemory getWritable() {
return wMem;
}
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java b/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
index e30c2ab..3a77ca5 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableMapHandleImpl.java
@@ -21,6 +21,7 @@ package org.apache.datasketches.memory.internal;
import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.WritableMapHandle;
+import org.apache.datasketches.memory.WritableMemory;
/**
* A Handle for a memory-mapped, writable file resource.
@@ -39,8 +40,8 @@ public final class WritableMapHandleImpl extends MapHandleImpl
}
@Override
- public WritableMemory get() {
- return (WritableMemory) super.get();
+ public WritableMemory getWritable() {
+ return wMem;
}
@Override
diff --git a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java b/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
index 85b8875..4bc97c4 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/WritableMemoryImpl.java
@@ -24,16 +24,13 @@ import static org.apache.datasketches.memory.internal.Util.nullCheck;
import static org.apache.datasketches.memory.internal.Util.zeroCheck;
import java.io.File;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.DefaultMemoryRequestServer;
-import org.apache.datasketches.memory.Handle;
import org.apache.datasketches.memory.MemoryRequestServer;
-import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.WritableMapHandle;
import org.apache.datasketches.memory.WritableDirectHandle;
+import org.apache.datasketches.memory.WritableMapHandle;
+import org.apache.datasketches.memory.WritableMemory;
/**
@@ -43,80 +40,30 @@ import org.apache.datasketches.memory.WritableDirectHandle;
* @author Roman Leventov
* @author Lee Rhodes
*/
-public abstract class WritableMemory extends Memory {
+public abstract class WritableMemoryImpl extends MemoryImpl implements WritableMemory {
//Pass-through ctor
- WritableMemory(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
+ WritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset,
final long capacityBytes) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
}
//BYTE BUFFER
- /**
- * Accesses the given ByteBuffer for write operations. The returned WritableMemory object has
- * the same byte order, as the given ByteBuffer, unless the capacity of the given ByteBuffer is
- * zero, then byte order of the returned WritableMemory object, as well as backing storage and
- * read-only status are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param byteBuf the given ByteBuffer
- * @return a new WritableMemory for write operations on the given ByteBuffer.
- */
- public static WritableMemory writableWrap(final ByteBuffer byteBuf) {
+ public static WritableMemoryImpl writableWrap(final ByteBuffer byteBuf) {
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteBuf.order());
}
- /**
- * Accesses the given ByteBuffer for write operations. The returned WritableMemory object has
- * the given byte order, ignoring the byte order of the given ByteBuffer. If the capacity of
- * the given ByteBuffer is zero the byte order of the returned WritableMemory object
- * (as well as backing storage) is unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param byteBuf the given ByteBuffer, must not be null
- * @param byteOrder the byte order to be used, which may be independent of the byte order
- * state of the given ByteBuffer
- * @return a new WritableMemory for write operations on the given ByteBuffer.
- */
- public static WritableMemory writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
+ public static WritableMemoryImpl writableWrap(final ByteBuffer byteBuf, final ByteOrder byteOrder) {
return BaseWritableMemoryImpl.wrapByteBuffer(byteBuf, false, byteOrder);
}
//MAP
- /**
- * Maps the entire given file into native-ordered WritableMemory for write operations
- * (including those > 2GB). Calling this method is equivalent to calling
- * {@link #writableMap(File, long, long, ByteOrder) map(file, 0, file.length(), ByteOrder.nativeOrder())}.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.map(...)</i>.
- * @param file the given file to map
- * @return WritableMapHandle for managing the mapped Memory.
- * Please read Javadocs for {@link Handle}.
- * @throws IOException file not found or a RuntimeException.
- */
- public static WritableMapHandle writableMap(final File file) throws IOException {
- return WritableMemory.writableMap(file, 0, file.length(), Util.nativeByteOrder);
+ public static WritableMapHandle writableMap(final File file) {
+ return WritableMemoryImpl.writableMap(file, 0, file.length(), Util.nativeByteOrder);
}
- /**
- * Maps the specified portion of the given file into Memory for write operations
- * (including those > 2GB).
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.map(...)</i>.
- * @param file the given file to map. It may not be null.
- * @param fileOffsetBytes the position in the given file in bytes. It may not be negative.
- * @param capacityBytes the size of the mapped Memory. It may not be negative or zero.
- * @param byteOrder the byte order to be used for the given file. It may not be null.
- * @return WritableMapHandleImpl for managing the mapped Memory.
- * Please read Javadocs for {@link Handle}.
- * @throws IOException file not found or RuntimeException, etc.
- */
public static WritableMapHandle writableMap(final File file, final long fileOffsetBytes,
- final long capacityBytes, final ByteOrder byteOrder) throws IOException {
+ final long capacityBytes, final ByteOrder byteOrder) {
zeroCheck(capacityBytes, "Capacity");
nullCheck(file, "file is null");
negativeCheck(fileOffsetBytes, "File offset is negative");
@@ -125,539 +72,186 @@ public abstract class WritableMemory extends Memory {
}
//ALLOCATE DIRECT
- /**
- * Allocates and provides access to capacityBytes directly in native (off-heap) memory
- * leveraging the WritableMemory API. Native byte order is assumed.
- * The allocated memory will be 8-byte aligned, but may not be page aligned.
- * If capacityBytes is zero, byte order, backing storage and read-only status
- * of the WritableMemory object, returned from {@link WritableHandle#get()} are unspecified.
- *
- * <p>The default MemoryRequestServer, which allocates any request for memory onto the heap,
- * will be used.</p>
- *
- * <p><b>NOTE:</b> Native/Direct memory acquired using Unsafe may have garbage in it.
- * It is the responsibility of the using class to clear this memory, if required,
- * and to call <i>close()</i> when done.</p>
- *
- * @param capacityBytes the size of the desired memory in bytes.
- * @return WritableDirectHandleImpl for this off-heap resource.
- * Please read Javadocs for {@link Handle}.
- */
public static WritableDirectHandle allocateDirect(final long capacityBytes) {
return allocateDirect(capacityBytes, null);
}
- /**
- * Allocates and provides access to capacityBytes directly in native (off-heap) memory
- * leveraging the WritableMemory API. The allocated memory will be 8-byte aligned, but may not
- * be page aligned. If capacityBytes is zero, byte order, backing storage and read-only status
- * of the WritableMemory object, returned from {@link WritableHandle#get()} are unspecified.
- *
- * <p><b>NOTE:</b> Native/Direct memory acquired using Unsafe may have garbage in it.
- * It is the responsibility of the using class to clear this memory, if required,
- * and to call <i>close()</i> when done.</p>
- *
- * @param capacityBytes the size of the desired memory in bytes.
- * @param memReqSvr A user-specified MemoryRequestServer.
- * This is a callback mechanism for a user client of direct memory to request more memory.
- * @return WritableHandle for this off-heap resource.
- * Please read Javadocs for {@link Handle}.
- */
public static WritableDirectHandle allocateDirect(final long capacityBytes,
final MemoryRequestServer memReqSvr) {
return BaseWritableMemoryImpl.wrapDirect(capacityBytes, Util.nativeByteOrder, memReqSvr);
}
//REGIONS
- /**
- * A writable region is a writable view of this object.
- * This returns a new <i>WritableMemory</i> representing the defined writable region with the
- * given offsetBytes and capacityBytes.
- * <ul>
- * <li>Returned object's origin = this objects' origin + <i>offsetBytes</i></li>
- * <li>Returned object's capacity = <i>capacityBytes</i></li>
- * </ul>
- * If the given capacityBytes is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- *
- * @param offsetBytes the starting offset with respect to this object.
- * @param capacityBytes the capacity of the returned object in bytes.
- * @return a new <i>WritableMemory</i> representing the defined writable region.
- */
- public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes);
-
- /**
- * A writable region is a writable view of this object.
- * This returns a new <i>WritableMemory</i> representing the defined writable region with the
- * given offsetBytes, capacityBytes and byte order.
- * <ul>
- * <li>Returned object's origin = this objects' origin + <i>offsetBytes</i></li>
- * <li>Returned object's capacity = <i>capacityBytes</i></li>
- * <li>Returned object's byte order = <i>byteOrder</i></li>
- * </ul>
- * If the given capacityBytes is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- *
- * @param offsetBytes the starting offset with respect to this object.
- * @param capacityBytes the capacity of the returned object in bytes.
- * @param byteOrder the given byte order
- * @return a new <i>WritableMemory</i> representing the defined writable region.
- */
- public abstract WritableMemory writableRegion(long offsetBytes, long capacityBytes,
+ @Override
+ public abstract WritableMemoryImpl writableRegion(long offsetBytes, long capacityBytes);
+
+ @Override
+ public abstract WritableMemoryImpl writableRegion(long offsetBytes, long capacityBytes,
ByteOrder byteOrder);
//AS BUFFER
- /**
- * Returns a new <i>WritableBuffer</i> with a writable view of this object.
- * <ul>
- * <li>Returned object's origin = this object's origin</li>
- * <li>Returned object's <i>start</i> = 0</li>
- * <li>Returned object's <i>position</i> = 0</li>
- * <li>Returned object's <i>end</i> = this object's capacity</li>
- * <li>Returned object's <i>capacity</i> = this object's capacity</li>
- * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
- * </ul>
- * If this object's capacity is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @return a new <i>WritableBuffer</i> with a view of this WritableMemory
- */
+ @Override
public abstract WritableBuffer asWritableBuffer();
- /**
- * Returns a new <i>WritableBuffer</i> with a writable view of this object
- * with the given byte order.
- * <ul>
- * <li>Returned object's origin = this object's origin</li>
- * <li>Returned object's <i>start</i> = 0</li>
- * <li>Returned object's <i>position</i> = 0</li>
- * <li>Returned object's <i>end</i> = this object's capacity</li>
- * <li>Returned object's <i>capacity</i> = this object's capacity</li>
- * <li>Returned object's <i>start</i>, <i>position</i> and <i>end</i> are mutable</li>
- * </ul>
- * If this object's capacity is zero, the returned object is effectively immutable and
- * the backing storage and byte order are unspecified.
- * @param byteOrder the given byte order
- * @return a new <i>WritableBuffer</i> with a view of this WritableMemory
- */
+ @Override
public abstract WritableBuffer asWritableBuffer(ByteOrder byteOrder);
//ALLOCATE HEAP VIA AUTOMATIC BYTE ARRAY
- /**
- * Creates on-heap WritableMemory with the given capacity and the native byte order. If the given
- * capacityBytes is zero, backing storage, byte order and read-only status of the returned
- * WritableMemory object are unspecified.
- * @param capacityBytes the given capacity in bytes.
- * @return a new WritableMemory for write operations on a new byte array.
- */
- public static WritableMemory allocate(final int capacityBytes) {
+ public static WritableMemoryImpl allocate(final int capacityBytes) {
final byte[] arr = new byte[capacityBytes];
return writableWrap(arr, Util.nativeByteOrder);
}
- /**
- * Creates on-heap WritableMemory with the given capacity and the given byte order. If the given
- * capacityBytes is zero, backing storage, byte order and read-only status of the returned
- * WritableMemory object are unspecified.
- * @param capacityBytes the given capacity in bytes.
- * @param byteOrder the given byte order to allocate new Memory object with.
- * @return a new WritableMemory for write operations on a new byte array.
- */
- public static WritableMemory allocate(final int capacityBytes, final ByteOrder byteOrder) {
+ public static WritableMemoryImpl allocate(final int capacityBytes, final ByteOrder byteOrder) {
final byte[] arr = new byte[capacityBytes];
return writableWrap(arr, byteOrder);
}
//ACCESS PRIMITIVE HEAP ARRAYS for write
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final boolean[] arr) {
+ public static WritableMemoryImpl writableWrap(final boolean[] arr) {
final long lengthBytes = arr.length << Prim.BOOLEAN.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final byte[] arr) {
- return WritableMemory.writableWrap(arr, 0, arr.length, Util.nativeByteOrder);
+ public static WritableMemoryImpl writableWrap(final byte[] arr) {
+ return WritableMemoryImpl.writableWrap(arr, 0, arr.length, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations with the given byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @param byteOrder the byte order to be used
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final byte[] arr, final ByteOrder byteOrder) {
- return WritableMemory.writableWrap(arr, 0, arr.length, byteOrder);
+ public static WritableMemoryImpl writableWrap(final byte[] arr, final ByteOrder byteOrder) {
+ return WritableMemoryImpl.writableWrap(arr, 0, arr.length, byteOrder);
}
- /**
- * Wraps the given primitive array for write operations with the given byte order. If the given
- * lengthBytes is zero, backing storage, byte order and read-only status of the returned
- * WritableMemory object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @param offsetBytes the byte offset into the given array
- * @param lengthBytes the number of bytes to include from the given array
- * @param byteOrder the byte order to be used
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
+ public static WritableMemoryImpl writableWrap(final byte[] arr, final int offsetBytes, final int lengthBytes,
final ByteOrder byteOrder) {
UnsafeUtil.checkBounds(offsetBytes, lengthBytes, arr.length);
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, byteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final char[] arr) {
+ public static WritableMemoryImpl writableWrap(final char[] arr) {
final long lengthBytes = arr.length << Prim.CHAR.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final short[] arr) {
+ public static WritableMemoryImpl writableWrap(final short[] arr) {
final long lengthBytes = arr.length << Prim.SHORT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final int[] arr) {
+ public static WritableMemoryImpl writableWrap(final int[] arr) {
final long lengthBytes = arr.length << Prim.INT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final long[] arr) {
+ public static WritableMemoryImpl writableWrap(final long[] arr) {
final long lengthBytes = arr.length << Prim.LONG.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final float[] arr) {
+ public static WritableMemoryImpl writableWrap(final float[] arr) {
final long lengthBytes = arr.length << Prim.FLOAT.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
- /**
- * Wraps the given primitive array for write operations assuming native byte order. If the array
- * size is zero, backing storage, byte order and read-only status of the returned WritableMemory
- * object are unspecified.
- *
- * <p><b>Note:</b> Always qualify this method with the class name, e.g.,
- * <i>WritableMemory.wrap(...)</i>.
- * @param arr the given primitive array.
- * @return a new WritableMemory for write operations on the given primitive array.
- */
- public static WritableMemory writableWrap(final double[] arr) {
+ public static WritableMemoryImpl writableWrap(final double[] arr) {
final long lengthBytes = arr.length << Prim.DOUBLE.shift();
return BaseWritableMemoryImpl.wrapHeapArray(arr, 0L, lengthBytes, false, Util.nativeByteOrder);
}
//END OF CONSTRUCTOR-TYPE METHODS
//PRIMITIVE putX() and putXArray()
- /**
- * Puts the boolean value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putBoolean(long offsetBytes, boolean value);
- /**
- * Puts the boolean array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetBooleans offset in array units
- * @param lengthBooleans number of array units to transfer
- */
+ @Override
public abstract void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans,
int lengthBooleans);
- /**
- * Puts the byte value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putByte(long offsetBytes, byte value);
- /**
- * Puts the byte array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetBytes offset in array units
- * @param lengthBytes number of array units to transfer
- */
+ @Override
public abstract void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes,
int lengthBytes);
- /**
- * Puts the char value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putChar(long offsetBytes, char value);
- /**
- * Puts the char array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetChars offset in array units
- * @param lengthChars number of array units to transfer
- */
+ @Override
public abstract void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars,
int lengthChars);
- /**
- * Encodes characters from the given CharSequence into UTF-8 bytes and puts them into this
- * <i>WritableMemory</i> begining at the given offsetBytes.
- * This is specifically designed to reduce the production of intermediate objects (garbage),
- * thus significantly reducing pressure on the JVM Garbage Collector.
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param src The source CharSequence to be encoded and put into this WritableMemory. It is
- * the responsibility of the caller to provide sufficient capacity in this
- * <i>WritableMemory</i> for the encoded Utf8 bytes. Characters outside the ASCII range can
- * require 2, 3 or 4 bytes per character to encode.
- * @return the number of bytes encoded
- */
+ @Override
public abstract long putCharsToUtf8(long offsetBytes, CharSequence src);
- /**
- * Puts the double value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putDouble(long offsetBytes, double value);
- /**
- * Puts the double array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetDoubles offset in array units
- * @param lengthDoubles number of array units to transfer
- */
+ @Override
public abstract void putDoubleArray(long offsetBytes, double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles);
- /**
- * Puts the float value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putFloat(long offsetBytes, float value);
- /**
- * Puts the float array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetFloats offset in array units
- * @param lengthFloats number of array units to transfer
- */
+ @Override
public abstract void putFloatArray(long offsetBytes, float[] srcArray,
final int srcOffsetFloats, final int lengthFloats);
- /**
- * Puts the int value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putInt(long offsetBytes, int value);
- /**
- * Puts the int array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetInts offset in array units
- * @param lengthInts number of array units to transfer
- */
+ @Override
public abstract void putIntArray(long offsetBytes, int[] srcArray,
final int srcOffsetInts, final int lengthInts);
- /**
- * Puts the long value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putLong(long offsetBytes, long value);
- /**
- * Puts the long array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetLongs offset in array units
- * @param lengthLongs number of array units to transfer
- */
+ @Override
public abstract void putLongArray(long offsetBytes, long[] srcArray,
final int srcOffsetLongs, final int lengthLongs);
- /**
- * Puts the short value at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param value the value to put
- */
+ @Override
public abstract void putShort(long offsetBytes, short value);
- /**
- * Puts the short array at the given offset
- * @param offsetBytes offset bytes relative to this <i>WritableMemory</i> start
- * @param srcArray The source array.
- * @param srcOffsetShorts offset in array units
- * @param lengthShorts number of array units to transfer
- */
+ @Override
public abstract void putShortArray(long offsetBytes, short[] srcArray,
final int srcOffsetShorts, final int lengthShorts);
//Atomic Methods
- /**
- * Atomically adds the given value to the long located at offsetBytes.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param delta the amount to add
- * @return the the previous value
- */
+ @Override
public abstract long getAndAddLong(long offsetBytes, long delta);
- /**
- * Atomically sets the current value at the memory location to the given updated value
- * if and only if the current value {@code ==} the expected value.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param expect the expected value
- * @param update the new value
- * @return {@code true} if successful. False return indicates that
- * the current value at the memory location was not equal to the expected value.
- */
+ @Override
public abstract boolean compareAndSwapLong(long offsetBytes, long expect, long update);
- /**
- * Atomically exchanges the given value with the current value located at offsetBytes.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param newValue new value
- * @return the previous value
- */
+ @Override
public abstract long getAndSetLong(long offsetBytes, long newValue);
//OTHER WRITE METHODS
- /**
- * Returns the primitive backing array, otherwise null.
- * @return the primitive backing array, otherwise null.
- */
+ @Override
public abstract Object getArray();
- /**
- * Clears all bytes of this Memory to zero
- */
+ @Override
public abstract void clear();
- /**
- * Clears a portion of this Memory to zero.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param lengthBytes the length in bytes
- */
+ @Override
public abstract void clear(long offsetBytes, long lengthBytes);
- /**
- * Clears the bits defined by the bitMask
- * @param offsetBytes offset bytes relative to this Memory start.
- * @param bitMask the bits set to one will be cleared
- */
+ @Override
public abstract void clearBits(long offsetBytes, byte bitMask);
- /**
- * Fills all bytes of this Memory region to the given byte value.
- * @param value the given byte value
- */
+ @Override
public abstract void fill(byte value);
- /**
- * Fills a portion of this Memory region to the given byte value.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param lengthBytes the length in bytes
- * @param value the given byte value
- */
+ @Override
public abstract void fill(long offsetBytes, long lengthBytes, byte value);
- /**
- * Sets the bits defined by the bitMask
- * @param offsetBytes offset bytes relative to this Memory start
- * @param bitMask the bits set to one will be set
- */
+ @Override
public abstract void setBits(long offsetBytes, byte bitMask);
//OTHER WRITABLE API METHODS
- /**
- * For Direct Memory only. Other types of backing resources will return null.
- * Gets the MemoryRequestServer object used by dynamic off-heap (Direct) memory objects
- * to request additional memory.
- * Set using {@link WritableMemory#allocateDirect(long, MemoryRequestServer)}.
- * If not explicity set, this returns the {@link DefaultMemoryRequestServer}.
- * @return the MemoryRequestServer object (if direct memory) or null.
- */
@Override
public MemoryRequestServer getMemoryRequestServer() {
return null;
diff --git a/src/main/java/org/apache/datasketches/memory/internal/package-info.java b/src/main/java/org/apache/datasketches/memory/internal/package-info.java
index 78a6a35..2f8471a 100644
--- a/src/main/java/org/apache/datasketches/memory/internal/package-info.java
+++ b/src/main/java/org/apache/datasketches/memory/internal/package-info.java
@@ -26,8 +26,8 @@
*
* <p>In addition, this package provides:</p>
*
- * <ul><li>Two different access APIs: read-only {@link org.apache.datasketches.memory.internal.Memory} and
- * {@link org.apache.datasketches.memory.internal.WritableMemory} for absolute offset access,
+ * <ul><li>Two different access APIs: read-only {@link org.apache.datasketches.memory.internal.MemoryImpl} and
+ * {@link org.apache.datasketches.memory.internal.WritableMemoryImpl} for absolute offset access,
* and read-only {@link org.apache.datasketches.memory.internal.Buffer} and
* {@link org.apache.datasketches.memory.internal.WritableBuffer}
* for relative positional access (similar to ByteBuffer).</li>
@@ -38,8 +38,8 @@
* <li>The conversion from Writable to read-only is just a cast, so no unnecessary objects are
* created. For example:
* <blockquote><pre>
- * WritableMemory wMem = ...
- * Memory mem = wMem;
+ * WritableMemoryImpl wMem = ...
+ * MemoryImpl mem = wMem;
* </pre></blockquote>
* </li>
*
@@ -51,7 +51,7 @@
* This virtually eliminates the possibility of accidentally writing into the memory space
* previously owned by a closed resource.</li>
*
- * <li>Improved performance over the prior Memory implementation.</li>
+ * <li>Improved performance over the prior MemoryImpl implementation.</li>
*
* <li>Cleaner internal architecture, which will make it easier to extend in the future.</li>
*
@@ -64,13 +64,13 @@
* byte-level read and write access. The four resources are:</p>
*
* <ul><li>Direct (a.k.a. Native) off-heap memory allocated by the user.</li>
- * <li>Memory-mapped files, both writable and read-only.</li>
+ * <li>MemoryImpl-mapped files, both writable and read-only.</li>
* <li>{@code ByteBuffers}, both heap-based and direct, writable and read-only.</li>
* <li>Heap-based primitive arrays, which can be accessed as writable or read-only.</li>
* </ul>
*
* <p>The two different access APIs are:</p>
- * <ul><li><i>Memory, WritableMemory</i>: Absolute offset addressing into a resource.</li>
+ * <ul><li><i>MemoryImpl, WritableMemoryImpl</i>: Absolute offset addressing into a resource.</li>
* <li><i>Buffer, WritableBuffer</i>: Position relative addressing into a resource.</li>
* </ul>
*
@@ -110,14 +110,14 @@
* The resource can also be explicitly closed by the user by calling {@code Handle.close()}.</p>
* <blockquote><pre>
* //Using try-with-resources block:
- * try (WritableyMapHandle handle = WritableMemory.map(File file)) {
- * WritableMemory wMem = handle.get();
+ * try (WritableyMapHandle handle = WritableMemoryImpl.map(File file)) {
+ * WritableMemoryImpl wMem = handle.get();
* doWork(wMem) // read and write to memory mapped file.
* }
*
* //Using explicit close():
- * WritableMapHandleImpl handle = WritableMemory.map(File file);
- * WritableMemory wMem = handle.get();
+ * WritableMapHandleImpl handle = WritableMemoryImpl.map(File file);
+ * WritableMemoryImpl wMem = handle.get();
* doWork(wMem) // read and write to memory mapped file.
* handle.close();
* </pre></blockquote>
@@ -125,7 +125,7 @@
* <p>Where it is desirable to pass ownership of the resource (and the {@code close()}
* responsibility) one can not use the TWR block. Instead:</p>
* <blockquote><pre>
- * WritableMapHandleImpl handler = WritableMemory.map(File file);
+ * WritableMapHandleImpl handler = WritableMemoryImpl.map(File file);
* doWorkAndClose(handle); //passes the handle to object that closes the resource.
* </pre></blockquote>
*
@@ -149,20 +149,20 @@
* hard-to-find bug.</li>
* </ul>
*
- *<p>Moving back and forth between <i>Memory</i> and <i>Buffer</i>:</p>
+ *<p>Moving back and forth between <i>MemoryImpl</i> and <i>Buffer</i>:</p>
*<blockquote><pre>
- * Memory mem = ...
+ * MemoryImpl mem = ...
* Buffer buf = mem.asBuffer();
* ...
- * Memory mem2 = buf.asMemory();
+ * MemoryImpl mem2 = buf.asMemory();
* ...
* </pre></blockquote>
*
* <p>Hierarchical memory regions can be easily created:</p>
* <blockquote><pre>
- * WritableMemory wMem = ...
- * WritableMemory wReg = wMem.writableRegion(offset, length); //OR
- * Memory reg = wMem.region(offset, length);
+ * WritableMemoryImpl wMem = ...
+ * WritableMemoryImpl wReg = wMem.writableRegion(offset, length); //OR
+ * MemoryImpl reg = wMem.region(offset, length);
* </pre></blockquote>
*
* <p>With asserts enabled in the JVM, all methods are checked for bounds and
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
index bfe2d05..a78e27f 100644
--- a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMapMemoryTest.java
@@ -33,7 +33,7 @@ import java.io.File;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.MapHandle;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -51,7 +51,7 @@ public class AllocateDirectMapMemoryTest {
@Test
public void simpleMap() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
- try (MapHandle rh = Memory.map(file)) {
+ try (MapHandle rh = MemoryImpl.map(file)) {
rh.close();
}
}
@@ -59,13 +59,13 @@ public class AllocateDirectMapMemoryTest {
@Test
public void testIllegalArguments() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
- try (MapHandle rh = Memory.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder())) {
+ try (MapHandle rh = MemoryImpl.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder())) {
fail("Failed: testIllegalArgumentException: Position was negative.");
} catch (IllegalArgumentException e) {
//ok
}
- try (MapHandle rh = Memory.map(file, 0, -1, ByteOrder.nativeOrder())) {
+ try (MapHandle rh = MemoryImpl.map(file, 0, -1, ByteOrder.nativeOrder())) {
fail("Failed: testIllegalArgumentException: Size was negative.");
} catch (IllegalArgumentException e) {
//ok
@@ -76,8 +76,8 @@ public class AllocateDirectMapMemoryTest {
public void testMapAndMultipleClose() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
- try (MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
- Memory map = rh.get();
+ try (MapHandle rh = MemoryImpl.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
+ MemoryImpl map = rh.get();
assertEquals(memCapacity, map.getCapacity());
rh.close();
rh.close();
@@ -91,8 +91,8 @@ public class AllocateDirectMapMemoryTest {
public void testReadFailAfterClose() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
- try (MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
- Memory mmf = rh.get();
+ try (MapHandle rh = MemoryImpl.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
+ MemoryImpl mmf = rh.get();
rh.close();
mmf.getByte(0);
} catch (AssertionError e) {
@@ -104,7 +104,7 @@ public class AllocateDirectMapMemoryTest {
public void testLoad() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
- try (MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
+ try (MapHandle rh = MemoryImpl.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
rh.load();
assertTrue(rh.isLoaded());
rh.close();
@@ -115,8 +115,8 @@ public class AllocateDirectMapMemoryTest {
public void testHandlerHandoffWithTWR() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
- Memory mem;
- try (MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
+ MemoryImpl mem;
+ try (MapHandle rh = MemoryImpl.map(file, 0, memCapacity, ByteOrder.nativeOrder())) {
rh.load();
assertTrue(rh.isLoaded());
hand = rh;
@@ -130,7 +130,7 @@ public class AllocateDirectMapMemoryTest {
public void testHandoffWithoutClose() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
long memCapacity = file.length();
- MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder());
+ MapHandle rh = MemoryImpl.map(file, 0, memCapacity, ByteOrder.nativeOrder());
rh.load();
assertTrue(rh.isLoaded());
hand = rh;
@@ -140,7 +140,7 @@ public class AllocateDirectMapMemoryTest {
@AfterClass
public void afterAllTests() {
if (hand != null) {
- Memory mem = hand.get();
+ MemoryImpl mem = hand.get();
if ((mem != null) && mem.isValid()) {
hand.close();
assertFalse(mem.isValid());
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
index 68de819..c487b91 100644
--- a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectMemoryTest.java
@@ -30,7 +30,7 @@ import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableDirectHandle;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
@@ -40,8 +40,8 @@ public class AllocateDirectMemoryTest {
@Test
public void simpleAllocateDirect() {
int longs = 32;
- WritableMemory wMem;
- try (WritableHandle wh = WritableMemory.allocateDirect(longs << 3)) {
+ WritableMemoryImpl wMem;
+ try (WritableHandle wh = WritableMemoryImpl.allocateDirect(longs << 3)) {
wMem = wh.get();
for (int i = 0; i<longs; i++) {
wMem.putLong(i << 3, i);
@@ -70,8 +70,8 @@ public class AllocateDirectMemoryTest {
public void checkDefaultMemoryRequestServer() {
int longs1 = 32;
int bytes1 = longs1 << 3;
- try (WritableHandle wh = WritableMemory.allocateDirect(bytes1)) {
- WritableMemory origWmem = wh.get();
+ try (WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes1)) {
+ WritableMemoryImpl origWmem = wh.get();
for (int i = 0; i<longs1; i++) { //puts data in wMem1
origWmem.putLong(i << 3, i);
assertEquals(origWmem.getLong(i << 3), i);
@@ -81,7 +81,7 @@ public class AllocateDirectMemoryTest {
int longs2 = 64;
int bytes2 = longs2 << 3;
MemoryRequestServer memReqSvr = origWmem.getMemoryRequestServer();
- WritableMemory newWmem = memReqSvr.request(bytes2);
+ WritableMemoryImpl newWmem = memReqSvr.request(bytes2);
assertFalse(newWmem.isDirect()); //on heap by default
for (int i = 0; i < longs2; i++) {
newWmem.putLong(i << 3, i);
@@ -95,8 +95,8 @@ public class AllocateDirectMemoryTest {
@Test
public void checkNullMemoryRequestServer() {
- try (WritableHandle wh = WritableMemory.allocateDirect(128, null)) {
- WritableMemory wmem = wh.get();
+ try (WritableHandle wh = WritableMemoryImpl.allocateDirect(128, null)) {
+ WritableMemoryImpl wmem = wh.get();
assertNotNull(wmem.getMemoryRequestServer());
}
}
@@ -106,7 +106,7 @@ public class AllocateDirectMemoryTest {
public void checkNonNativeDirect() { //not allowed in public API
try (WritableDirectHandle h = ReflectUtil.wrapDirect(8, Util.nonNativeByteOrder, null)) {
//BaseWritableMemoryImpl.wrapDirect(8, Util.nonNativeByteOrder, null)) {
- WritableMemory wmem = h.get();
+ WritableMemoryImpl wmem = h.get();
wmem.putChar(0, (char) 1);
assertEquals(wmem.getByte(1), (byte) 1);
}
@@ -115,7 +115,7 @@ public class AllocateDirectMemoryTest {
@Test
public void checkExplicitClose() {
final long cap = 128;
- try (WritableDirectHandle wdh = WritableMemory.allocateDirect(cap)) {
+ try (WritableDirectHandle wdh = WritableMemoryImpl.allocateDirect(cap)) {
wdh.close(); //explicit close. Does the work of closing
} //end of scope call to Cleaner/Deallocator also will be redundant
}
@@ -123,7 +123,7 @@ public class AllocateDirectMemoryTest {
@SuppressWarnings("static-access")
@AfterClass
public void checkDirectCounter() {
- WritableMemory mem = WritableMemory.writableWrap(new byte[8]);
+ WritableMemoryImpl mem = WritableMemoryImpl.writableWrap(new byte[8]);
long count = mem.getCurrentDirectMemoryAllocations();
if (count != 0) {
println(""+count);
diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
index a6b8640..5761068 100644
--- a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java
@@ -39,10 +39,10 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.apache.datasketches.memory.WritableMapHandle;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -82,8 +82,8 @@ public class AllocateDirectWritableMapMemoryTest {
@Test
public void simpleMap() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
- try (MapHandle h = Memory.map(file); WritableMapHandle wh = (WritableMapHandle) h) {
- Memory mem = h.get();
+ try (MapHandle h = MemoryImpl.map(file); WritableMapHandle wh = (WritableMapHandle) h) {
+ MemoryImpl mem = h.get();
byte[] bytes = new byte[(int)mem.getCapacity()];
mem.getByteArray(0, bytes, 0, bytes.length);
String text = new String(bytes, UTF_8);
@@ -117,11 +117,11 @@ public class AllocateDirectWritableMapMemoryTest {
try (
WritableMapHandle dstHandle
- = WritableMemory.writableMap(file, 0, bytes, ByteOrder.nativeOrder());
- WritableHandle srcHandle = WritableMemory.allocateDirect(bytes)) {
+ = WritableMemoryImpl.writableMap(file, 0, bytes, ByteOrder.nativeOrder());
+ WritableHandle srcHandle = WritableMemoryImpl.allocateDirect(bytes)) {
- WritableMemory dstMem = dstHandle.get();
- WritableMemory srcMem = srcHandle.get();
+ WritableMemoryImpl dstMem = dstHandle.get();
+ WritableMemoryImpl srcMem = srcHandle.get();
for (long i = 0; i < longs; i++) {
srcMem.putLong(i << 3, i); //load source with consecutive longs
@@ -152,8 +152,8 @@ public class AllocateDirectWritableMapMemoryTest {
file.deleteOnExit(); //comment out if you want to examine the file.
final long bytes = 8;
- try (WritableMapHandle h = WritableMemory.writableMap(file, 0L, bytes, Util.nonNativeByteOrder)) {
- WritableMemory wmem = h.get();
+ try (WritableMapHandle h = WritableMemoryImpl.writableMap(file, 0L, bytes, Util.nonNativeByteOrder)) {
+ WritableMemoryImpl wmem = h.get();
wmem.putChar(0, (char) 1);
assertEquals(wmem.getByte(1), (byte) 1);
}
@@ -164,14 +164,14 @@ public class AllocateDirectWritableMapMemoryTest {
public void testMapException() throws IOException {
File dummy = createFile("dummy.txt", ""); //zero length
//throws java.lang.reflect.InvocationTargetException
- Memory.map(dummy, 0, dummy.length(), ByteOrder.nativeOrder());
+ MemoryImpl.map(dummy, 0, dummy.length(), ByteOrder.nativeOrder());
}
@Test(expectedExceptions = ReadOnlyException.class)
public void simpleMap2() throws IOException {
File file = getResourceFile("GettysburgAddress.txt");
assertTrue(isFileReadOnly(file));
- try (WritableMapHandle rh = WritableMemory.writableMap(file)) { //throws
+ try (WritableMapHandle rh = WritableMemoryImpl.writableMap(file)) { //throws
//
}
}
@@ -179,7 +179,7 @@ public class AllocateDirectWritableMapMemoryTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkOverLength() {
File file = getResourceFile("GettysburgAddress.txt");
- try (WritableMapHandle rh = WritableMemory.writableMap(file, 0, 1 << 20, ByteOrder.nativeOrder())) {
+ try (WritableMapHandle rh = WritableMemoryImpl.writableMap(file, 0, 1 << 20, ByteOrder.nativeOrder())) {
//
} catch (IOException e) {
throw new RuntimeException(e);
@@ -196,8 +196,8 @@ public class AllocateDirectWritableMapMemoryTest {
byte[] correctByteArr = correctStr.getBytes(UTF_8);
long corrBytes = correctByteArr.length;
- try (MapHandle rh = Memory.map(origFile, 0, origBytes, ByteOrder.nativeOrder())) {
- Memory map = rh.get();
+ try (MapHandle rh = MemoryImpl.map(origFile, 0, origBytes, ByteOrder.nativeOrder())) {
+ MemoryImpl map = rh.get();
rh.load();
assertTrue(rh.isLoaded());
//confirm orig string
@@ -207,9 +207,9 @@ public class AllocateDirectWritableMapMemoryTest {
assertEquals(bufStr, origStr);
}
- try (WritableMapHandle wrh = WritableMemory.writableMap(origFile, 0, corrBytes,
+ try (WritableMapHandle wrh = WritableMemoryImpl.writableMap(origFile, 0, corrBytes,
ByteOrder.nativeOrder())) {
- WritableMemory wMap = wrh.get();
+ WritableMemoryImpl wMap = wrh.get();
wrh.load();
assertTrue(wrh.isLoaded());
// over write content
@@ -240,7 +240,7 @@ public class AllocateDirectWritableMapMemoryTest {
@Test
public void checkExplicitClose() throws Exception {
File file = getResourceFile("GettysburgAddress.txt");
- try (MapHandle wmh = Memory.map(file)) {
+ try (MapHandle wmh = MemoryImpl.map(file)) {
wmh.close(); //explicit close.
} //end of scope call to Cleaner/Deallocator also will be redundant
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java b/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
index 51b2ded..0f5f44e 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BaseBufferTest.java
@@ -23,8 +23,8 @@ import static org.testng.Assert.fail;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -35,7 +35,7 @@ public class BaseBufferTest {
@Test
public void checkLimits() {
- Buffer buf = Memory.wrap(new byte[100]).asBuffer();
+ Buffer buf = MemoryImpl.wrap(new byte[100]).asBuffer();
buf.setStartPositionEnd(40, 45, 50);
buf.setStartPositionEnd(0, 0, 100);
try {
@@ -48,7 +48,7 @@ public class BaseBufferTest {
@Test
public void checkLimitsAndCheck() {
- Buffer buf = Memory.wrap(new byte[100]).asBuffer();
+ Buffer buf = MemoryImpl.wrap(new byte[100]).asBuffer();
buf.setAndCheckStartPositionEnd(40, 45, 50);
buf.setAndCheckStartPositionEnd(0, 0, 100);
try {
@@ -76,13 +76,13 @@ public class BaseBufferTest {
@Test
public void checkCheckValid() {
- WritableMemory wmem;
+ WritableMemoryImpl wmem;
Buffer buf;
- try (WritableHandle hand = WritableMemory.allocateDirect(100)) {
+ try (WritableHandle hand = WritableMemoryImpl.allocateDirect(100)) {
wmem = hand.get();
buf = wmem.asBuffer();
}
@SuppressWarnings("unused")
- Memory mem = buf.asMemory();
+ MemoryImpl mem = buf.asMemory();
}
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java b/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
index 2ba50b8..919265c 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BaseStateTest.java
@@ -28,12 +28,12 @@ import static org.testng.Assert.fail;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Prim;
import org.apache.datasketches.memory.internal.StepBoolean;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -47,8 +47,8 @@ public class BaseStateTest {
@Test
public void checkIsSameResource() {
- WritableMemory wmem = WritableMemory.allocate(16);
- Memory mem = wmem;
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(16);
+ MemoryImpl mem = wmem;
assertFalse(wmem.isSameResource(null));
assertTrue(wmem.isSameResource(mem));
@@ -61,7 +61,7 @@ public class BaseStateTest {
@Test
public void checkNotEqualTo() {
byte[] arr = new byte[8];
- Memory mem = Memory.wrap(arr);
+ MemoryImpl mem = MemoryImpl.wrap(arr);
assertFalse(mem.equalTo(0, arr, 0, 8));
}
@@ -90,14 +90,14 @@ public class BaseStateTest {
@Test
public void checkGetNativeBaseOffset_Heap() throws Exception {
- WritableMemory wmem = WritableMemory.allocate(8); //heap
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(8); //heap
final long offset = ReflectUtil.getNativeBaseOffset(wmem);
assertEquals(offset, 0L);
}
@Test
public void checkIsByteOrderCompatible() {
- WritableMemory wmem = WritableMemory.allocate(8);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(8);
assertTrue(wmem.isByteOrderCompatible(ByteOrder.nativeOrder()));
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java b/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
index b1cb7aa..4a19f56 100644
--- a/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
+++ b/src/test/java/org/apache/datasketches/memory/test/Buffer2Test.java
@@ -27,10 +27,10 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -84,7 +84,7 @@ public class Buffer2Test {
byteArray[i] = i;
}
- Buffer buffer = Memory.wrap(byteArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(byteArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(byteArray[i++], buffer.getByte());
@@ -107,7 +107,7 @@ public class Buffer2Test {
charArray[i] = i;
}
- Buffer buffer = Memory.wrap(charArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(charArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(charArray[i++], buffer.getChar());
@@ -127,7 +127,7 @@ public class Buffer2Test {
shortArray[i] = i;
}
- Buffer buffer = Memory.wrap(shortArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(shortArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(shortArray[i++], buffer.getShort());
@@ -147,7 +147,7 @@ public class Buffer2Test {
intArray[i] = i;
}
- Buffer buffer = Memory.wrap(intArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(intArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(intArray[i++], buffer.getInt());
@@ -167,7 +167,7 @@ public class Buffer2Test {
longArray[i] = i;
}
- Buffer buffer = Memory.wrap(longArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(longArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(longArray[i++], buffer.getLong());
@@ -187,7 +187,7 @@ public class Buffer2Test {
floatArray[i] = i;
}
- Buffer buffer = Memory.wrap(floatArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(floatArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(floatArray[i++], buffer.getFloat());
@@ -207,7 +207,7 @@ public class Buffer2Test {
doubleArray[i] = i;
}
- Buffer buffer = Memory.wrap(doubleArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(doubleArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(doubleArray[i++], buffer.getDouble());
@@ -229,7 +229,7 @@ public class Buffer2Test {
}
}
- Buffer buffer = Memory.wrap(booleanArray).asBuffer();
+ Buffer buffer = MemoryImpl.wrap(booleanArray).asBuffer();
int i = 0;
while (buffer.hasRemaining()) {
assertEquals(booleanArray[i++], buffer.getBoolean());
@@ -348,7 +348,7 @@ public class Buffer2Test {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- Memory mem = Memory.wrap(arr);
+ MemoryImpl mem = MemoryImpl.wrap(arr);
Buffer buf = mem.asBuffer();
Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
for (int i = 0; i < n2; i++) {
@@ -370,7 +370,7 @@ public class Buffer2Test {
bb.position(10);
Buffer buffer = Buffer.wrap(bb);
- Memory memory = buffer.asMemory();
+ MemoryImpl memory = buffer.asMemory();
assertEquals(buffer.getCapacity(), memory.getCapacity());
@@ -408,7 +408,7 @@ public class Buffer2Test {
@Test
public void testWritableDuplicate() {
- WritableMemory wmem = WritableMemory.writableWrap(new byte[1]);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(new byte[1]);
WritableBuffer wbuf = wmem.asWritableBuffer();
WritableBuffer wbuf2 = wbuf.writableDuplicate();
assertEquals(wbuf2.getCapacity(), 1);
@@ -419,14 +419,14 @@ public class Buffer2Test {
@Test
public void checkIndependence() {
int cap = 64;
- WritableMemory wmem = WritableMemory.allocate(cap);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(cap);
WritableBuffer wbuf1 = wmem.asWritableBuffer();
WritableBuffer wbuf2 = wmem.asWritableBuffer();
assertFalse(wbuf1 == wbuf2);
assertTrue(wbuf1.isSameResource(wbuf2));
- WritableMemory reg1 = wmem.writableRegion(0, cap);
- WritableMemory reg2 = wmem.writableRegion(0, cap);
+ WritableMemoryImpl reg1 = wmem.writableRegion(0, cap);
+ WritableMemoryImpl reg2 = wmem.writableRegion(0, cap);
assertFalse(reg1 == reg2);
assertTrue(reg1.isSameResource(reg2));
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
index 0970ffb..356862d 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferBoundaryCheckTest.java
@@ -19,13 +19,13 @@
package org.apache.datasketches.memory.test;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class BufferBoundaryCheckTest {
- private final WritableMemory writableMemory = WritableMemory.allocate(8);
+ private final WritableMemoryImpl writableMemory = WritableMemoryImpl.allocate(8);
@Test
public void testGetBoolean() {
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
index 50b6557..d71419a 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferInvariantsTest.java
@@ -27,7 +27,7 @@ import java.nio.ByteBuffer;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -93,7 +93,7 @@ public class BufferInvariantsTest {
@Test
public void testBuf() {
int n = 25;
- WritableBuffer buf = WritableMemory.allocate(n).asWritableBuffer();
+ WritableBuffer buf = WritableMemoryImpl.allocate(n).asWritableBuffer();
for (byte i = 0; i < n; i++) { buf.putByte(i); }
buf.setPosition(0);
assertEquals(buf.getPosition(), 0);
@@ -162,8 +162,8 @@ public class BufferInvariantsTest {
@Test
public void checkLimitsDirect() {
- try (WritableHandle hand = WritableMemory.allocateDirect(100)) {
- WritableMemory wmem = hand.get();
+ try (WritableHandle hand = WritableMemoryImpl.allocateDirect(100)) {
+ WritableMemoryImpl wmem = hand.get();
Buffer buf = wmem.asBuffer();
buf.setStartPositionEnd(40, 45, 50);
buf.setStartPositionEnd(0, 0, 100);
@@ -233,8 +233,8 @@ public class BufferInvariantsTest {
@Test
public void testBufDirect() {
int n = 25;
- try (WritableHandle whand = WritableMemory.allocateDirect(n)) {
- WritableMemory wmem = whand.get();
+ try (WritableHandle whand = WritableMemoryImpl.allocateDirect(n)) {
+ WritableMemoryImpl wmem = whand.get();
WritableBuffer buf = wmem.asWritableBuffer();
for (byte i = 0; i < n; i++) { buf.putByte(i); }
buf.setPosition(0);
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
index 24f195f..6d67e67 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferReadWriteSafetyTest.java
@@ -24,7 +24,7 @@ import java.nio.ByteBuffer;
import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -158,19 +158,19 @@ public class BufferReadWriteSafetyTest {
@Test(expectedExceptions = AssertionError.class)
public void testWritableMemoryAsBuffer() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemory.allocate(8).asBuffer();
+ WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asBuffer();
buf1.putInt(1);
}
@Test(expectedExceptions = AssertionError.class)
public void testWritableBufferRegion() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemory.allocate(8).asWritableBuffer().region();
+ WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asWritableBuffer().region();
buf1.putInt(1);
}
@Test(expectedExceptions = AssertionError.class)
public void testWritableBufferDuplicate() {
- WritableBuffer buf1 = (WritableBuffer) WritableMemory.allocate(8).asWritableBuffer().duplicate();
+ WritableBuffer buf1 = (WritableBuffer) WritableMemoryImpl.allocate(8).asWritableBuffer().duplicate();
buf1.putInt(1);
}
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/BufferTest.java b/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
index 9c1481a..38a4f31 100644
--- a/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/BufferTest.java
@@ -27,9 +27,9 @@ import java.util.List;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
@@ -39,8 +39,8 @@ public class BufferTest {
@Test
public void checkDirectRoundTrip() {
int n = 1024; //longs
- try (WritableHandle wh = WritableMemory.allocateDirect(n * 8)) {
- WritableMemory wmem = wh.get();
+ try (WritableHandle wh = WritableMemoryImpl.allocateDirect(n * 8)) {
+ WritableMemoryImpl wmem = wh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
@@ -56,7 +56,7 @@ public class BufferTest {
@Test
public void checkAutoHeapRoundTrip() {
int n = 1024; //longs
- WritableBuffer wbuf = WritableMemory.allocate(n * 8).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
}
@@ -71,7 +71,7 @@ public class BufferTest {
public void checkArrayWrap() {
int n = 1024; //longs
byte[] arr = new byte[n * 8];
- WritableBuffer wbuf = WritableMemory.writableWrap(arr).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
for (int i = 0; i < n; i++) {
wbuf.putLong(i);
}
@@ -80,29 +80,29 @@ public class BufferTest {
long v = wbuf.getLong();
assertEquals(v, i);
}
- Buffer buf = Memory.wrap(arr).asBuffer();
+ Buffer buf = MemoryImpl.wrap(arr).asBuffer();
buf.resetPosition();
for (int i = 0; i < n; i++) {
long v = buf.getLong();
assertEquals(v, i);
}
// Check Zero length array wraps
- Memory mem = Memory.wrap(new byte[0]);
+ MemoryImpl mem = MemoryImpl.wrap(new byte[0]);
Buffer buffZeroLengthArrayWrap = mem.asBuffer();
assertEquals(buffZeroLengthArrayWrap.getCapacity(), 0);
// check 0 length array wraps
List<Buffer> buffersToCheck = Lists.newArrayList();
- buffersToCheck.add(WritableMemory.allocate(0).asBuffer());
+ buffersToCheck.add(WritableMemoryImpl.allocate(0).asBuffer());
buffersToCheck.add(WritableBuffer.wrap(ByteBuffer.allocate(0)));
buffersToCheck.add(Buffer.wrap(ByteBuffer.allocate(0)));
- buffersToCheck.add(Memory.wrap(new boolean[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new byte[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new char[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new short[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new int[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new long[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new float[0]).asBuffer());
- buffersToCheck.add(Memory.wrap(new double[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new boolean[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new byte[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new char[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new short[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new int[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new long[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new float[0]).asBuffer());
+ buffersToCheck.add(MemoryImpl.wrap(new double[0]).asBuffer());
//Check the buffer lengths
for (Buffer buffer : buffersToCheck) {
assertEquals(buffer.getCapacity(), 0);
@@ -151,7 +151,7 @@ public class BufferTest {
long v = bb.getLong(i * 8);
assertEquals(v, i);
}
- Buffer buf1 = Memory.wrap(arr).asBuffer();
+ Buffer buf1 = MemoryImpl.wrap(arr).asBuffer();
for (int i = 0; i < n; i++) { //read from wrapped arr
long v = buf1.getLong();
assertEquals(v, i);
@@ -231,7 +231,7 @@ public class BufferTest {
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableBuffer wbuf = WritableMemory.allocate(n * 8).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.allocate(n * 8).asWritableBuffer();
wbuf.putLongArray(arr, 0, n);
long[] arr2 = new long[n];
wbuf.resetPosition();
@@ -248,7 +248,7 @@ public class BufferTest {
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- Buffer buf = Memory.wrap(arr).asBuffer();
+ Buffer buf = MemoryImpl.wrap(arr).asBuffer();
buf.setPosition(n2 * 8);
Buffer reg = buf.region();
for (int i = 0; i < n2; i++) {
@@ -264,7 +264,7 @@ public class BufferTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableBuffer wbuf = WritableMemory.writableWrap(arr).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(arr).asWritableBuffer();
for (int i = 0; i < n; i++) {
assertEquals(wbuf.getLong(), i); //write all
//println("" + wmem.getLong(i * 8));
@@ -284,11 +284,11 @@ public class BufferTest {
public void checkParentUseAfterFree() {
int bytes = 64 * 8;
@SuppressWarnings("resource") //intentionally not using try-with-resources here
- WritableHandle wh = WritableMemory.allocateDirect(bytes);
- WritableMemory wmem = wh.get();
+ WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
+ WritableMemoryImpl wmem = wh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
wh.close();
- //with -ea assert: Memory not valid.
+ //with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
wbuf.getLong();
}
@@ -297,19 +297,19 @@ public class BufferTest {
@Test(expectedExceptions = AssertionError.class)
public void checkRegionUseAfterFree() {
int bytes = 64;
- WritableHandle wh = WritableMemory.allocateDirect(bytes);
- Memory wmem = wh.get();
+ WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
+ MemoryImpl wmem = wh.get();
Buffer reg = wmem.asBuffer().region();
wh.close();
- //with -ea assert: Memory not valid.
+ //with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
reg.getByte();
}
@Test(expectedExceptions = AssertionError.class)
public void checkBaseBufferInvariants() {
- WritableBuffer wbuf = WritableMemory.allocate(64).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.allocate(64).asWritableBuffer();
wbuf.setStartPositionEnd(1, 0, 2); //out of order
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java b/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
index f3b78ee..2f7f4fb 100644
--- a/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/CommonBufferTest.java
@@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -32,8 +32,8 @@ public class CommonBufferTest {
@Test
public void checkSetGet() {
int memCapacity = 60; //must be at least 60
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetTests(buf);
@@ -134,8 +134,8 @@ public class CommonBufferTest {
@Test
public void checkSetGetArrays() {
int memCapacity = 32;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetArraysTests(buf);
@@ -231,8 +231,8 @@ public class CommonBufferTest {
@Test
public void checkSetGetPartialArraysWithOffset() {
int memCapacity = 32;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
setGetPartialArraysWithOffsetTests(buf);
@@ -325,8 +325,8 @@ public class CommonBufferTest {
@Test
public void checkSetClearMemoryRegions() {
int memCapacity = 64; //must be 64
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh1.get();
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
@@ -414,8 +414,8 @@ public class CommonBufferTest {
@Test
public void checkToHexStringAllMem() {
int memCapacity = 48; //must be 48
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh1.get();
WritableBuffer buf = mem.asWritableBuffer();
assertEquals(buf.getCapacity(), memCapacity);
toHexStringAllMemTests(buf); //requires println enabled to visually check
diff --git a/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
index 5cde091..5e237b6 100644
--- a/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/CommonMemoryTest.java
@@ -28,7 +28,7 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -37,14 +37,14 @@ public class CommonMemoryTest {
@Test
public void checkSetGet() {
int memCapacity = 16; //must be at least 8
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
assertEquals(mem.getCapacity(), memCapacity);
setGetTests(mem);
}
}
- public static void setGetTests(WritableMemory mem) {
+ public static void setGetTests(WritableMemoryImpl mem) {
mem.putBoolean(0, true);
assertEquals(mem.getBoolean(0), true);
mem.putBoolean(0, false);
@@ -89,14 +89,14 @@ public class CommonMemoryTest {
@Test
public void checkSetGetArrays() {
int memCapacity = 32;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
assertEquals(memCapacity, mem.getCapacity());
setGetArraysTests(mem);
}
}
- public static void setGetArraysTests(WritableMemory mem) {
+ public static void setGetArraysTests(WritableMemoryImpl mem) {
int accessCapacity = (int)mem.getCapacity();
int words = 4;
@@ -169,14 +169,14 @@ public class CommonMemoryTest {
@Test
public void checkSetGetPartialArraysWithOffset() {
int memCapacity = 32;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
assertEquals(memCapacity, mem.getCapacity());
setGetPartialArraysWithOffsetTests(mem);
}
}
- public static void setGetPartialArraysWithOffsetTests(WritableMemory mem) {
+ public static void setGetPartialArraysWithOffsetTests(WritableMemoryImpl mem) {
int items= 4;
boolean[] srcArray1 = {true, false, true, false};
boolean[] dstArray1 = new boolean[items];
@@ -246,15 +246,15 @@ public class CommonMemoryTest {
@Test
public void checkSetClearIsBits() {
int memCapacity = 8;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
assertEquals(memCapacity, mem.getCapacity());
mem.clear();
setClearIsBitsTests(mem);
}
}
- public static void setClearIsBitsTests(WritableMemory mem) {
+ public static void setClearIsBitsTests(WritableMemoryImpl mem) {
//single bits
for (int i = 0; i < 8; i++) {
long bitMask = (1 << i);
@@ -287,14 +287,14 @@ public class CommonMemoryTest {
@Test
public void checkAtomicMethods() {
int memCapacity = 8;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
assertEquals(mem.getCapacity(), memCapacity);
atomicMethodTests(mem);
}
}
- public static void atomicMethodTests(WritableMemory mem) {
+ public static void atomicMethodTests(WritableMemoryImpl mem) {
mem.putLong(0, 500);
mem.getAndAddLong(0, 1);
assertEquals(mem.getLong(0), 501);
@@ -314,8 +314,8 @@ public class CommonMemoryTest {
@Test
public void checkSetClearMemoryRegions() {
int memCapacity = 64; //must be 64
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh1.get();
setClearMemoryRegionsTests(mem); //requires println enabled to visually check
for (int i = 0; i < memCapacity; i++) {
@@ -325,7 +325,7 @@ public class CommonMemoryTest {
}
//enable println stmts to visually check
- public static void setClearMemoryRegionsTests(WritableMemory mem) {
+ public static void setClearMemoryRegionsTests(WritableMemoryImpl mem) {
int accessCapacity = (int)mem.getCapacity();
//define regions
@@ -385,14 +385,14 @@ public class CommonMemoryTest {
@Test
public void checkToHexStringAllMem() {
int memCapacity = 48; //must be 48
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh1.get();
toHexStringAllMemTests(mem); //requires println enabled to visually check
}
}
//enable println to visually check
- public static void toHexStringAllMemTests(WritableMemory mem) {
+ public static void toHexStringAllMemTests(WritableMemoryImpl mem) {
int memCapacity = (int)mem.getCapacity();
for (int i = 0; i < memCapacity; i++) {
diff --git a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java b/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
index f82561a..e81d369 100644
--- a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/CopyMemoryOverlapTest.java
@@ -22,8 +22,8 @@ package org.apache.datasketches.memory.test;
import static org.testng.Assert.assertEquals;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -65,7 +65,7 @@ public class CopyMemoryOverlapTest {
}
private static final void copyUsingDirectMemory(long copyLongs, double overlap, boolean copyUp) {
- println("Copy Using Direct Memory");
+ println("Copy Using Direct MemoryImpl");
long overlapLongs = (long) (overlap * copyLongs);
long backingLongs = (2 * copyLongs) - overlapLongs;
@@ -93,8 +93,8 @@ public class CopyMemoryOverlapTest {
println("CopyUp : " + copyUp);
println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
- try (WritableHandle backHandle = WritableMemory.allocateDirect(backingBytes)) {
- WritableMemory backingMem = backHandle.get();
+ try (WritableHandle backHandle = WritableMemoryImpl.allocateDirect(backingBytes)) {
+ WritableMemoryImpl backingMem = backHandle.get();
fill(backingMem); //fill mem with 0 thru copyLongs -1
//listMem(backingMem, "Original");
backingMem.copyTo(fromOffsetBytes, backingMem, toOffsetBytes, copyBytes);
@@ -105,7 +105,7 @@ public class CopyMemoryOverlapTest {
}
private static final void copyUsingDirectRegions(long copyLongs, double overlap, boolean copyUp) {
- println("Copy Using Direct Memory");
+ println("Copy Using Direct MemoryImpl");
long overlapLongs = (long) (overlap * copyLongs);
long backingLongs = (2 * copyLongs) - overlapLongs;
@@ -133,12 +133,12 @@ public class CopyMemoryOverlapTest {
println("CopyUp : " + copyUp);
println("Backing longs: " + backingLongs + "\t bytes: " + backingBytes);
- try (WritableHandle backHandle = WritableMemory.allocateDirect(backingBytes)) {
- WritableMemory backingMem = backHandle.get();
+ try (WritableHandle backHandle = WritableMemoryImpl.allocateDirect(backingBytes)) {
+ WritableMemoryImpl backingMem = backHandle.get();
fill(backingMem); //fill mem with 0 thru copyLongs -1
//listMem(backingMem, "Original");
- WritableMemory reg1 = backingMem.writableRegion(fromOffsetBytes, copyBytes);
- WritableMemory reg2 = backingMem.writableRegion(toOffsetBytes, copyBytes);
+ WritableMemoryImpl reg1 = backingMem.writableRegion(fromOffsetBytes, copyBytes);
+ WritableMemoryImpl reg2 = backingMem.writableRegion(toOffsetBytes, copyBytes);
reg1.copyTo(0, reg2, 0, copyBytes);
//listMem(backingMem, "After");
@@ -147,13 +147,13 @@ public class CopyMemoryOverlapTest {
println("");
}
- private static final void fill(WritableMemory wmem) {
+ private static final void fill(WritableMemoryImpl wmem) {
long longs = wmem.getCapacity() >>> 3;
for (long i = 0; i < longs; i++) { wmem.putLong(i << 3, i); } //fill with 0 .. (longs - 1)
//checkMemLongs(wmem, 0L, 0L, longs);
}
- private static final void checkMemLongs(Memory mem, long fromOffsetLongs, long toOffsetLongs, long copyLongs) {
+ private static final void checkMemLongs(MemoryImpl mem, long fromOffsetLongs, long toOffsetLongs, long copyLongs) {
for (long i = 0; i < copyLongs; i++) {
long memVal = mem.getLong((toOffsetLongs + i) << 3);
assertEquals(memVal, fromOffsetLongs + i);
@@ -161,7 +161,7 @@ public class CopyMemoryOverlapTest {
}
@SuppressWarnings("unused")
- private static final void listMem(Memory mem, String comment) {
+ private static final void listMem(MemoryImpl mem, String comment) {
println(comment);
println("Idx\tValue");
long longs = mem.getCapacity() >>> 3;
diff --git a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
index b322a1e..4a760bc 100644
--- a/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/CopyMemoryTest.java
@@ -25,8 +25,8 @@ import static org.testng.Assert.assertEquals;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -37,9 +37,9 @@ public class CopyMemoryTest {
public void heapWSource() {
int k1 = 1 << 20; //longs
int k2 = 2 * k1;
- WritableMemory srcMem = genMem(k1, false); //!empty
+ WritableMemoryImpl srcMem = genMem(k1, false); //!empty
//println(srcMem.toHexString("src: ", 0, k1 << 3));
- WritableMemory dstMem = genMem(k2, true);
+ WritableMemoryImpl dstMem = genMem(k2, true);
srcMem.copyTo(0, dstMem, k1 << 3, k1 << 3);
//println(dstMem.toHexString("dst: ", 0, k2 << 3));
check(dstMem, k1, k1, 1);
@@ -49,8 +49,8 @@ public class CopyMemoryTest {
public void heapROSource() {
int k1 = 1 << 20; //longs
int k2 = 2 * k1;
- Memory srcMem = genMem(k1, false); //!empty
- WritableMemory dstMem = genMem(k2, true);
+ MemoryImpl srcMem = genMem(k1, false); //!empty
+ WritableMemoryImpl dstMem = genMem(k2, true);
srcMem.copyTo(0, dstMem, k1 << 3, k1 << 3);
check(dstMem, k1, k1, 1);
}
@@ -60,8 +60,8 @@ public class CopyMemoryTest {
int k1 = 1 << 20; //longs
int k2 = 2 * k1;
try (WritableHandle wrh = genWRH(k1, false)) {
- WritableMemory srcMem = wrh.get();
- WritableMemory dstMem = genMem(k2, true);
+ WritableMemoryImpl srcMem = wrh.get();
+ WritableMemoryImpl dstMem = genMem(k2, true);
srcMem.copyTo(0, dstMem, k1 << 3, k1 << 3);
check(dstMem, k1, k1, 1);
}
@@ -72,8 +72,8 @@ public class CopyMemoryTest {
int k1 = 1 << 20; //longs
int k2 = 2 * k1;
try (WritableHandle wrh = genWRH(k1, false)) {
- Memory srcMem = wrh.get();
- WritableMemory dstMem = genMem(k2, true);
+ MemoryImpl srcMem = wrh.get();
+ WritableMemoryImpl dstMem = genMem(k2, true);
srcMem.copyTo(0, dstMem, k1 << 3, k1 << 3);
check(dstMem, k1, k1, 1);
}
@@ -83,10 +83,10 @@ public class CopyMemoryTest {
public void heapWSrcRegion() {
int k1 = 1 << 20; //longs
//gen baseMem of k1 longs w data
- WritableMemory baseMem = genMem(k1, false); //!empty
+ WritableMemoryImpl baseMem = genMem(k1, false); //!empty
//gen src region of k1/2 longs, off= k1/2
- WritableMemory srcReg = baseMem.writableRegion((k1/2) << 3, (k1/2) << 3);
- WritableMemory dstMem = genMem(2 * k1, true); //empty
+ WritableMemoryImpl srcReg = baseMem.writableRegion((k1/2) << 3, (k1/2) << 3);
+ WritableMemoryImpl dstMem = genMem(2 * k1, true); //empty
srcReg.copyTo(0, dstMem, k1 << 3, (k1/2) << 3);
//println(dstMem.toHexString("dstMem: ", k1 << 3, (k1/2) << 3));
check(dstMem, k1, k1/2, (k1/2) + 1);
@@ -96,10 +96,10 @@ public class CopyMemoryTest {
public void heapROSrcRegion() {
int k1 = 1 << 20; //longs
//gen baseMem of k1 longs w data
- WritableMemory baseMem = genMem(k1, false); //!empty
+ WritableMemoryImpl baseMem = genMem(k1, false); //!empty
//gen src region of k1/2 longs, off= k1/2
- Memory srcReg = baseMem.region((k1/2) << 3, (k1/2) << 3);
- WritableMemory dstMem = genMem(2 * k1, true); //empty
+ MemoryImpl srcReg = baseMem.region((k1/2) << 3, (k1/2) << 3);
+ WritableMemoryImpl dstMem = genMem(2 * k1, true); //empty
srcReg.copyTo(0, dstMem, k1 << 3, (k1/2) << 3);
check(dstMem, k1, k1/2, (k1/2) + 1);
}
@@ -109,10 +109,10 @@ public class CopyMemoryTest {
int k1 = 1 << 20; //longs
//gen baseMem of k1 longs w data, direct
try (WritableHandle wrh = genWRH(k1, false)) {
- Memory baseMem = wrh.get();
+ MemoryImpl baseMem = wrh.get();
//gen src region of k1/2 longs, off= k1/2
- Memory srcReg = baseMem.region((k1/2) << 3, (k1/2) << 3);
- WritableMemory dstMem = genMem(2 * k1, true); //empty
+ MemoryImpl srcReg = baseMem.region((k1/2) << 3, (k1/2) << 3);
+ WritableMemoryImpl dstMem = genMem(2 * k1, true); //empty
srcReg.copyTo(0, dstMem, k1 << 3, (k1/2) << 3);
check(dstMem, k1, k1/2, (k1/2) + 1);
}
@@ -123,8 +123,8 @@ public class CopyMemoryTest {
byte[] bytes = new byte[((UNSAFE_COPY_THRESHOLD_BYTES * 5) / 2) + 1];
ThreadLocalRandom.current().nextBytes(bytes);
byte[] referenceBytes = bytes.clone();
- Memory referenceMem = Memory.wrap(referenceBytes);
- WritableMemory mem = WritableMemory.writableWrap(bytes);
+ MemoryImpl referenceMem = MemoryImpl.wrap(referenceBytes);
+ WritableMemoryImpl mem = WritableMemoryImpl.writableWrap(bytes);
long copyLen = UNSAFE_COPY_THRESHOLD_BYTES * 2;
mem.copyTo(0, mem, UNSAFE_COPY_THRESHOLD_BYTES / 2, copyLen);
Assert.assertEquals(0, mem.compareTo(UNSAFE_COPY_THRESHOLD_BYTES / 2, copyLen, referenceMem, 0,
@@ -136,15 +136,15 @@ public class CopyMemoryTest {
byte[] bytes = new byte[((UNSAFE_COPY_THRESHOLD_BYTES * 5) / 2) + 1];
ThreadLocalRandom.current().nextBytes(bytes);
byte[] referenceBytes = bytes.clone();
- Memory referenceMem = Memory.wrap(referenceBytes);
- WritableMemory mem = WritableMemory.writableWrap(bytes);
+ MemoryImpl referenceMem = MemoryImpl.wrap(referenceBytes);
+ WritableMemoryImpl mem = WritableMemoryImpl.writableWrap(bytes);
long copyLen = UNSAFE_COPY_THRESHOLD_BYTES * 2;
mem.copyTo(UNSAFE_COPY_THRESHOLD_BYTES / 2, mem, 0, copyLen);
Assert.assertEquals(0, mem.compareTo(0, copyLen, referenceMem, UNSAFE_COPY_THRESHOLD_BYTES / 2,
copyLen));
}
- private static void check(Memory mem, int offsetLongs, int lengthLongs, int startValue) {
+ private static void check(MemoryImpl mem, int offsetLongs, int lengthLongs, int startValue) {
int offBytes = offsetLongs << 3;
for (long i = 0; i < lengthLongs; i++) {
assertEquals(mem.getLong(offBytes + (i << 3)), i + startValue);
@@ -152,8 +152,8 @@ public class CopyMemoryTest {
}
private static WritableHandle genWRH(int longs, boolean empty) {
- WritableHandle wrh = WritableMemory.allocateDirect(longs << 3);
- WritableMemory mem = wrh.get();
+ WritableHandle wrh = WritableMemoryImpl.allocateDirect(longs << 3);
+ WritableMemoryImpl mem = wrh.get();
if (empty) {
mem.clear();
} else {
@@ -163,8 +163,8 @@ public class CopyMemoryTest {
}
- private static WritableMemory genMem(int longs, boolean empty) {
- WritableMemory mem = WritableMemory.allocate(longs << 3);
+ private static WritableMemoryImpl genMem(int longs, boolean empty) {
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(longs << 3);
if (!empty) {
for (int i = 0; i < longs; i++) { mem.putLong(i << 3, i + 1); }
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java b/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
index cbff8d5..c0438a7 100644
--- a/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/ExampleMemoryRequestServerTest.java
@@ -25,7 +25,7 @@ import java.util.IdentityHashMap;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -43,7 +43,7 @@ public class ExampleMemoryRequestServerTest {
public void checkExampleMemoryRequestServer1() {
int bytes = 8;
ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer();
- WritableMemory wMem = svr.request(bytes);
+ WritableMemoryImpl wMem = svr.request(bytes);
MemoryClient client = new MemoryClient(wMem);
client.process();
svr.cleanup();
@@ -60,8 +60,8 @@ public class ExampleMemoryRequestServerTest {
public void checkExampleMemoryRequestServer2() {
int bytes = 8;
ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer();
- try (WritableHandle handle = WritableMemory.allocateDirect(bytes, svr)) {
- WritableMemory wMem = handle.get();
+ try (WritableHandle handle = WritableMemoryImpl.allocateDirect(bytes, svr)) {
+ WritableMemoryImpl wMem = handle.get();
MemoryClient client = new MemoryClient(wMem);
client.process();
svr.cleanup();
@@ -72,7 +72,7 @@ public class ExampleMemoryRequestServerTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkZeroCapacity() {
ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer();
- WritableMemory.allocateDirect(0, svr);
+ WritableMemoryImpl.allocateDirect(0, svr);
}
/**
@@ -83,10 +83,10 @@ public class ExampleMemoryRequestServerTest {
* <p>In reality, these memory requests should be quite rare.</p>
*/
static class MemoryClient {
- WritableMemory smallMem;
+ WritableMemoryImpl smallMem;
MemoryRequestServer svr;
- MemoryClient(WritableMemory wmem) {
+ MemoryClient(WritableMemoryImpl wmem) {
smallMem = wmem;
svr = wmem.getMemoryRequestServer();
}
@@ -96,7 +96,7 @@ public class ExampleMemoryRequestServerTest {
smallMem.fill((byte) 1); //fill it, but not big enough
println(smallMem.toHexString("Small", 0, (int)cap1));
- WritableMemory bigMem = svr.request(2 * cap1); //get bigger mem
+ WritableMemoryImpl bigMem = svr.request(2 * cap1); //get bigger mem
long cap2 = bigMem.getCapacity();
smallMem.copyTo(0, bigMem, 0, cap1); //copy data from small to big
svr.requestClose(smallMem, bigMem); //done with smallMem, release it
@@ -104,7 +104,7 @@ public class ExampleMemoryRequestServerTest {
bigMem.fill(cap1, cap1, (byte) 2); //fill the rest of bigMem, still not big enough
println(bigMem.toHexString("Big", 0, (int)cap2));
- WritableMemory giantMem = svr.request(2 * cap2); //get giant mem
+ WritableMemoryImpl giantMem = svr.request(2 * cap2); //get giant mem
long cap3 = giantMem.getCapacity();
bigMem.copyTo(0, giantMem, 0, cap2); //copy data from small to big
svr.requestClose(bigMem, giantMem); //done with bigMem, release it
@@ -120,13 +120,13 @@ public class ExampleMemoryRequestServerTest {
* possibly manage the continuous requests for larger memory.
*/
public static class ExampleMemoryRequestServer implements MemoryRequestServer {
- IdentityHashMap<WritableMemory, WritableHandle> map = new IdentityHashMap<>();
+ IdentityHashMap<WritableMemoryImpl, WritableHandle> map = new IdentityHashMap<>();
@SuppressWarnings("resource")
@Override
- public WritableMemory request(long capacityBytes) {
- WritableHandle handle = WritableMemory.allocateDirect(capacityBytes, this);
- WritableMemory wmem = handle.get();
+ public WritableMemoryImpl request(long capacityBytes) {
+ WritableHandle handle = WritableMemoryImpl.allocateDirect(capacityBytes, this);
+ WritableMemoryImpl wmem = handle.get();
map.put(wmem, handle); //We track the newly allocated memory and its handle.
return wmem;
}
@@ -134,7 +134,7 @@ public class ExampleMemoryRequestServerTest {
@SuppressWarnings("resource")
@Override
//here we actually release it, in reality it might be a lot more complex.
- public void requestClose(WritableMemory memToRelease, WritableMemory newMemory) {
+ public void requestClose(WritableMemoryImpl memToRelease, WritableMemoryImpl newMemory) {
if (memToRelease != null) {
WritableHandle handle = map.get(memToRelease);
if (handle != null && handle.get() == memToRelease) {
diff --git a/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java b/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
index 2b6b36a..1653bc6 100644
--- a/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/IgnoredArrayOverflowTest.java
@@ -20,7 +20,7 @@
package org.apache.datasketches.memory.test;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Ignore;
@@ -31,11 +31,11 @@ import org.testng.annotations.Test;
public class IgnoredArrayOverflowTest {
private WritableHandle h;
- private WritableMemory memory;
+ private WritableMemoryImpl memory;
@BeforeClass
public void allocate() {
- h = WritableMemory.allocateDirect(Integer.MAX_VALUE + 100L);
+ h = WritableMemoryImpl.allocateDirect(Integer.MAX_VALUE + 100L);
memory = h.get();
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java b/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
index 58bc367..c25ea06 100644
--- a/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/LeafImplTest.java
@@ -34,7 +34,7 @@ import org.apache.datasketches.memory.WritableDirectHandle;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.apache.datasketches.memory.WritableMapHandle;
import org.testng.annotations.Test;
@@ -50,14 +50,14 @@ public class LeafImplTest {
public void checkDirectLeafs() {
long off = 0;
long cap = 128;
- try (WritableDirectHandle wdh = WritableMemory.allocateDirect(cap)) {
- WritableMemory memLE = wdh.get();
+ try (WritableDirectHandle wdh = WritableMemoryImpl.allocateDirect(cap)) {
+ WritableMemoryImpl memLE = wdh.get();
memLE.putShort(0, (short) 1);
checkDirectImpl(memLE, off, cap);
}
}
- private static void checkDirectImpl(WritableMemory mem, long off, long cap) {
+ private static void checkDirectImpl(WritableMemoryImpl mem, long off, long cap) {
assertEquals(mem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(mem.writableRegion(off, cap, BE).getShort(0), 256);
assertEquals(mem.asWritableBuffer(LE).getShort(0), 1);
@@ -86,7 +86,7 @@ public class LeafImplTest {
//assertTrue(buf.getUnsafeObject() == null);
assertTrue(buf.isValid() == true);
- WritableMemory nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
+ WritableMemoryImpl nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
assertEquals(nnMem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnMem.writableRegion(off, cap, BE).getShort(0), 256);
@@ -134,15 +134,15 @@ public class LeafImplTest {
assertTrue(file.isFile());
file.deleteOnExit(); //comment out if you want to examine the file.
- try (WritableMapHandle wmh = WritableMemory.writableMap(file, off, cap, Util.nativeByteOrder)) {
- WritableMemory mem = wmh.get();
+ try (WritableMapHandle wmh = WritableMemoryImpl.writableMap(file, off, cap, Util.nativeByteOrder)) {
+ WritableMemoryImpl mem = wmh.get();
mem.putShort(0, (short) 1);
assertEquals(mem.getByte(0), (byte) 1);
checkMapImpl(mem, off, cap);
}
}
- private static void checkMapImpl(WritableMemory mem, long off, long cap) {
+ private static void checkMapImpl(WritableMemoryImpl mem, long off, long cap) {
assertEquals(mem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(mem.writableRegion(off, cap, BE).getShort(0), 256);
assertEquals(mem.asWritableBuffer(LE).getShort(0), 1);
@@ -171,7 +171,7 @@ public class LeafImplTest {
//assertTrue(buf.getUnsafeObject() == null);
assertTrue(buf.isValid() == true);
- WritableMemory nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
+ WritableMemoryImpl nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
assertEquals(nnMem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnMem.writableRegion(off, cap, BE).getShort(0), 256);
@@ -209,17 +209,17 @@ public class LeafImplTest {
ByteBuffer bb = ByteBuffer.allocate((int)cap);
bb.order(ByteOrder.nativeOrder());
bb.putShort(0, (short) 1);
- WritableMemory mem = WritableMemory.writableWrap(bb);
+ WritableMemoryImpl mem = WritableMemoryImpl.writableWrap(bb);
checkByteBufferImpl(mem, off, cap, false);
ByteBuffer dbb = ByteBuffer.allocateDirect((int)cap);
dbb.order(ByteOrder.nativeOrder());
dbb.putShort(0, (short) 1);
- mem = WritableMemory.writableWrap(dbb);
+ mem = WritableMemoryImpl.writableWrap(dbb);
checkByteBufferImpl(mem, off, cap, true);
}
- private static void checkByteBufferImpl(WritableMemory mem, long off, long cap, boolean direct) {
+ private static void checkByteBufferImpl(WritableMemoryImpl mem, long off, long cap, boolean direct) {
assertEquals(mem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(mem.writableRegion(off, cap, BE).getShort(0), 256);
assertEquals(mem.asWritableBuffer(LE).getShort(0), 1);
@@ -260,7 +260,7 @@ public class LeafImplTest {
}
assertTrue(buf.isValid() == true);
- WritableMemory nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
+ WritableMemoryImpl nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
assertEquals(nnMem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnMem.writableRegion(off, cap, BE).getShort(0), 256);
@@ -307,12 +307,12 @@ public class LeafImplTest {
public void checkHeapLeafs() {
long off = 0;
long cap = 128;
- WritableMemory mem = WritableMemory.allocate((int)cap);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate((int)cap);
mem.putShort(0, (short) 1);
checkHeapImpl(mem, off, cap);
}
- private static void checkHeapImpl(WritableMemory mem, long off, long cap) {
+ private static void checkHeapImpl(WritableMemoryImpl mem, long off, long cap) {
assertEquals(mem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(mem.writableRegion(off, cap, BE).getShort(0), 256);
assertEquals(mem.asWritableBuffer(LE).getShort(0), 1);
@@ -341,7 +341,7 @@ public class LeafImplTest {
//assertTrue(buf.getUnsafeObject() != null);
assertTrue(buf.isValid() == true);
- WritableMemory nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
+ WritableMemoryImpl nnMem = mem.writableRegion(off, cap, Util.nonNativeByteOrder);
assertEquals(nnMem.writableRegion(off, cap, LE).getShort(0), 1);
assertEquals(nnMem.writableRegion(off, cap, BE).getShort(0), 256);
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java b/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
index ade4ec4..4137c71 100644
--- a/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/MemoryBoundaryCheckTest.java
@@ -20,13 +20,13 @@
package org.apache.datasketches.memory.test;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class MemoryBoundaryCheckTest {
- private final WritableBuffer writableBuffer = WritableMemory.allocate(8).asWritableBuffer();
+ private final WritableBuffer writableBuffer = WritableMemoryImpl.allocate(8).asWritableBuffer();
@Test
public void testGetBoolean() {
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java b/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
index b712060..ece9cdf 100644
--- a/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/MemoryReadWriteSafetyTest.java
@@ -26,17 +26,17 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.MapHandle;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class MemoryReadWriteSafetyTest {
- // Test various operations with read-only Memory
+ // Test various operations with read-only MemoryImpl
- final WritableMemory mem = (WritableMemory) Memory.wrap(new byte[8]);
+ final WritableMemoryImpl mem = (WritableMemoryImpl) MemoryImpl.wrap(new byte[8]);
@Test(expectedExceptions = AssertionError.class)
public void testPutByte() {
@@ -122,73 +122,73 @@ public class MemoryReadWriteSafetyTest {
@Test(expectedExceptions = AssertionError.class)
public void testWritableMemoryRegion() {
- WritableMemory mem1 = (WritableMemory) WritableMemory.allocate(8).region(0, 8);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) WritableMemoryImpl.allocate(8).region(0, 8);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testByteArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new byte[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new byte[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testByteArrayWrapWithBO() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new byte[8], ByteOrder.nativeOrder());
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new byte[8], ByteOrder.nativeOrder());
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testByteArrayWrapWithOffsetsAndBO() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new byte[8], 0, 4, ByteOrder.nativeOrder());
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new byte[8], 0, 4, ByteOrder.nativeOrder());
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testBooleanArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new boolean[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new boolean[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testShortArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new short[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new short[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testCharArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new char[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new char[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testIntArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new int[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new int[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testLongArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new long[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new long[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testFloatArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new float[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new float[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testDoubleArrayWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(new double[8]);
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(new double[8]);
mem1.putInt(0, 1);
}
@Test(expectedExceptions = AssertionError.class)
public void testByteBufferWrap() {
- WritableMemory mem1 = (WritableMemory) Memory.wrap(ByteBuffer.allocate(8));
+ WritableMemoryImpl mem1 = (WritableMemoryImpl) MemoryImpl.wrap(ByteBuffer.allocate(8));
mem1.putInt(0, 1);
}
@@ -200,8 +200,8 @@ public class MemoryReadWriteSafetyTest {
try (RandomAccessFile raf = new RandomAccessFile(tempFile, "rw")) {
raf.setLength(8);
//System.out.println(UtilTest.getFileAttributes(tempFile));
- try (MapHandle h = Memory.map(tempFile)) {
- ((WritableMemory) h.get()).putInt(0, 1);
+ try (MapHandle h = MemoryImpl.map(tempFile)) {
+ ((WritableMemoryImpl) h.get()).putInt(0, 1);
}
}
}
@@ -212,8 +212,8 @@ public class MemoryReadWriteSafetyTest {
File tempFile = File.createTempFile("test", "test");
tempFile.deleteOnExit();
new RandomAccessFile(tempFile, "rw").setLength(8);
- try (MapHandle h = Memory.map(tempFile, 0, 4, ByteOrder.nativeOrder())) {
- ((WritableMemory) h.get()).putInt(0, 1);
+ try (MapHandle h = MemoryImpl.map(tempFile, 0, 4, ByteOrder.nativeOrder())) {
+ ((WritableMemoryImpl) h.get()).putInt(0, 1);
}
}
@@ -223,7 +223,7 @@ public class MemoryReadWriteSafetyTest {
File tempFile = File.createTempFile("test", "test");
tempFile.deleteOnExit();
new RandomAccessFile(tempFile, "rw").setLength(8);
- try (MapHandle unused = Memory.map(tempFile, 0, 16, ByteOrder.nativeOrder())) {
+ try (MapHandle unused = MemoryImpl.map(tempFile, 0, 16, ByteOrder.nativeOrder())) {
}
}
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
index bbe3e24..e882209 100644
--- a/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/MemoryTest.java
@@ -38,9 +38,9 @@ import java.util.List;
import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.WritableDirectHandle;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -58,8 +58,8 @@ public class MemoryTest {
@Test
public void checkDirectRoundTrip() {
int n = 1024; //longs
- try (WritableHandle wh = WritableMemory.allocateDirect(n * 8)) {
- WritableMemory mem = wh.get();
+ try (WritableHandle wh = WritableMemoryImpl.allocateDirect(n * 8)) {
+ WritableMemoryImpl mem = wh.get();
for (int i = 0; i < n; i++) {
mem.putLong(i * 8, i);
}
@@ -73,7 +73,7 @@ public class MemoryTest {
@Test
public void checkAutoHeapRoundTrip() {
int n = 1024; //longs
- WritableMemory wmem = WritableMemory.allocate(n * 8);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(n * 8);
for (int i = 0; i < n; i++) {
wmem.putLong(i * 8, i);
}
@@ -87,7 +87,7 @@ public class MemoryTest {
public void checkArrayWrap() {
int n = 1024; //longs
byte[] arr = new byte[n * 8];
- WritableMemory wmem = WritableMemory.writableWrap(arr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr);
for (int i = 0; i < n; i++) {
wmem.putLong(i * 8, i);
}
@@ -95,20 +95,20 @@ public class MemoryTest {
long v = wmem.getLong(i * 8);
assertEquals(v, i);
}
- Memory mem = Memory.wrap(arr, ByteOrder.nativeOrder());
+ MemoryImpl mem = MemoryImpl.wrap(arr, ByteOrder.nativeOrder());
for (int i = 0; i < n; i++) {
long v = mem.getLong(i * 8);
assertEquals(v, i);
}
// check 0 length array wraps
- Memory memZeroLengthArrayBoolean = WritableMemory.writableWrap(new boolean[0]);
- Memory memZeroLengthArrayByte = WritableMemory.writableWrap(new byte[0]);
- Memory memZeroLengthArrayChar = WritableMemory.writableWrap(new char[0]);
- Memory memZeroLengthArrayShort = WritableMemory.writableWrap(new short[0]);
- Memory memZeroLengthArrayInt = WritableMemory.writableWrap(new int[0]);
- Memory memZeroLengthArrayLong = WritableMemory.writableWrap(new long[0]);
- Memory memZeroLengthArrayFloat = WritableMemory.writableWrap(new float[0]);
- Memory memZeroLengthArrayDouble = WritableMemory.writableWrap(new double[0]);
+ MemoryImpl memZeroLengthArrayBoolean = WritableMemoryImpl.writableWrap(new boolean[0]);
+ MemoryImpl memZeroLengthArrayByte = WritableMemoryImpl.writableWrap(new byte[0]);
+ MemoryImpl memZeroLengthArrayChar = WritableMemoryImpl.writableWrap(new char[0]);
+ MemoryImpl memZeroLengthArrayShort = WritableMemoryImpl.writableWrap(new short[0]);
+ MemoryImpl memZeroLengthArrayInt = WritableMemoryImpl.writableWrap(new int[0]);
+ MemoryImpl memZeroLengthArrayLong = WritableMemoryImpl.writableWrap(new long[0]);
+ MemoryImpl memZeroLengthArrayFloat = WritableMemoryImpl.writableWrap(new float[0]);
+ MemoryImpl memZeroLengthArrayDouble = WritableMemoryImpl.writableWrap(new double[0]);
assertEquals(memZeroLengthArrayBoolean.getCapacity(), 0);
assertEquals(memZeroLengthArrayByte.getCapacity(), 0);
assertEquals(memZeroLengthArrayChar.getCapacity(), 0);
@@ -119,28 +119,28 @@ public class MemoryTest {
assertEquals(memZeroLengthArrayDouble.getCapacity(), 0);
// check 0 length array wraps
- List<Memory> memoryToCheck = Lists.newArrayList();
- memoryToCheck.add(WritableMemory.allocate(0));
- memoryToCheck.add(WritableMemory.writableWrap(ByteBuffer.allocate(0)));
- memoryToCheck.add(WritableMemory.writableWrap(new boolean[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new byte[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new char[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new short[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new int[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new long[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new float[0]));
- memoryToCheck.add(WritableMemory.writableWrap(new double[0]));
- memoryToCheck.add(Memory.wrap(ByteBuffer.allocate(0)));
- memoryToCheck.add(Memory.wrap(new boolean[0]));
- memoryToCheck.add(Memory.wrap(new byte[0]));
- memoryToCheck.add(Memory.wrap(new char[0]));
- memoryToCheck.add(Memory.wrap(new short[0]));
- memoryToCheck.add(Memory.wrap(new int[0]));
- memoryToCheck.add(Memory.wrap(new long[0]));
- memoryToCheck.add(Memory.wrap(new float[0]));
- memoryToCheck.add(Memory.wrap(new double[0]));
- //Check the Memory lengths
- for (Memory memory : memoryToCheck) {
+ List<MemoryImpl> memoryToCheck = Lists.newArrayList();
+ memoryToCheck.add(WritableMemoryImpl.allocate(0));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(ByteBuffer.allocate(0)));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new boolean[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new byte[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new char[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new short[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new int[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new long[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new float[0]));
+ memoryToCheck.add(WritableMemoryImpl.writableWrap(new double[0]));
+ memoryToCheck.add(MemoryImpl.wrap(ByteBuffer.allocate(0)));
+ memoryToCheck.add(MemoryImpl.wrap(new boolean[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new byte[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new char[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new short[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new int[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new long[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new float[0]));
+ memoryToCheck.add(MemoryImpl.wrap(new double[0]));
+ //Check the MemoryImpl lengths
+ for (MemoryImpl memory : memoryToCheck) {
assertEquals(memory.getCapacity(), 0);
}
}
@@ -151,7 +151,7 @@ public class MemoryTest {
byte[] arr = new byte[n * 8];
ByteBuffer bb = ByteBuffer.wrap(arr);
bb.order(ByteOrder.nativeOrder());
- WritableMemory wmem = WritableMemory.writableWrap(bb);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bb);
for (int i = 0; i < n; i++) { //write to wmem
wmem.putLong(i * 8, i);
}
@@ -163,13 +163,13 @@ public class MemoryTest {
long v = bb.getLong(i * 8);
assertEquals(v, i);
}
- Memory mem1 = Memory.wrap(arr);
+ MemoryImpl mem1 = MemoryImpl.wrap(arr);
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;
+ MemoryImpl mem = wmem;
for (int i = 0; i < n; i++) {
long v = mem.getLong(i * 8);
assertEquals(v, i);
@@ -181,7 +181,7 @@ public class MemoryTest {
int n = 1024; //longs
ByteBuffer bb = ByteBuffer.allocateDirect(n * 8);
bb.order(ByteOrder.nativeOrder());
- WritableMemory wmem = WritableMemory.writableWrap(bb);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bb);
for (int i = 0; i < n; i++) { //write to wmem
wmem.putLong(i * 8, i);
}
@@ -193,13 +193,13 @@ public class MemoryTest {
long v = bb.getLong(i * 8);
assertEquals(v, i);
}
- Memory mem1 = Memory.wrap(bb);
+ MemoryImpl mem1 = MemoryImpl.wrap(bb);
for (int i = 0; i < n; i++) { //read from wrapped bb RO
long v = mem1.getLong(i * 8);
assertEquals(v, i);
}
//convert to RO
- Memory mem = wmem;
+ MemoryImpl mem = wmem;
for (int i = 0; i < n; i++) {
long v = mem.getLong(i * 8);
assertEquals(v, i);
@@ -211,7 +211,7 @@ public class MemoryTest {
int n = 1024; //longs
ByteBuffer bb = ByteBuffer.allocate(n * 8);
bb.order(ByteOrder.BIG_ENDIAN);
- Memory mem = Memory.wrap(bb);
+ MemoryImpl mem = MemoryImpl.wrap(bb);
assertFalse(mem.getTypeByteOrder() == Util.nativeByteOrder);
assertEquals(mem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@@ -224,7 +224,7 @@ public class MemoryTest {
bb.position(64);
ByteBuffer slice = bb.slice().asReadOnlyBuffer();
slice.order(ByteOrder.nativeOrder());
- Memory mem = Memory.wrap(slice);
+ MemoryImpl mem = MemoryImpl.wrap(slice);
for (int i = 0; i < 64; i++) {
assertEquals(mem.getByte(i), 64 + i);
}
@@ -237,7 +237,7 @@ public class MemoryTest {
int n = 1024; //longs
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableMemory wmem = WritableMemory.allocate(n * 8);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(n * 8);
wmem.putLongArray(0, arr, 0, n);
long[] arr2 = new long[n];
wmem.getLongArray(0, arr2, 0, n);
@@ -252,8 +252,8 @@ public class MemoryTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- Memory mem = Memory.wrap(arr);
- Memory reg = mem.region(n2 * 8, n2 * 8); //top half
+ MemoryImpl mem = MemoryImpl.wrap(arr);
+ MemoryImpl reg = mem.region(n2 * 8, n2 * 8); //top half
for (int i = 0; i < n2; i++) {
long v = reg.getLong(i * 8);
long e = i + n2;
@@ -267,8 +267,8 @@ public class MemoryTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- Memory mem = Memory.wrap(arr);
- Memory reg = mem.region(n2 * 8, n2 * 8, Util.nonNativeByteOrder); //top half
+ MemoryImpl mem = MemoryImpl.wrap(arr);
+ MemoryImpl reg = mem.region(n2 * 8, n2 * 8, Util.nonNativeByteOrder); //top half
for (int i = 0; i < n2; i++) {
long v = Long.reverseBytes(reg.getLong(i * 8));
long e = i + n2;
@@ -282,13 +282,13 @@ public class MemoryTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableMemory wmem = WritableMemory.writableWrap(arr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr);
for (int i = 0; i < n; i++) {
assertEquals(wmem.getLong(i * 8), i);
//println("" + wmem.getLong(i * 8));
}
//println("");
- WritableMemory reg = wmem.writableRegion(n2 * 8, n2 * 8);
+ WritableMemoryImpl reg = wmem.writableRegion(n2 * 8, n2 * 8);
for (int i = 0; i < n2; i++) { reg.putLong(i * 8, i); }
for (int i = 0; i < n; i++) {
assertEquals(wmem.getLong(i * 8), i % 8);
@@ -302,13 +302,13 @@ public class MemoryTest {
int n2 = n / 2;
long[] arr = new long[n];
for (int i = 0; i < n; i++) { arr[i] = i; }
- WritableMemory wmem = WritableMemory.writableWrap(arr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr);
for (int i = 0; i < n; i++) {
assertEquals(wmem.getLong(i * 8), i);
//println("" + wmem.getLong(i * 8));
}
//println("");
- WritableMemory reg = wmem.writableRegion(n2 * 8, n2 * 8, Util.nonNativeByteOrder);
+ WritableMemoryImpl reg = wmem.writableRegion(n2 * 8, n2 * 8, Util.nonNativeByteOrder);
for (int i = 0; i < n2; i++) { reg.putLong(i * 8, i); }
for (int i = 0; i < n; i++) {
long v = wmem.getLong(i * 8);
@@ -325,10 +325,10 @@ public class MemoryTest {
public void checkParentUseAfterFree() {
int bytes = 64 * 8;
@SuppressWarnings("resource") //intentionally not using try-with-resouces here
- WritableHandle wh = WritableMemory.allocateDirect(bytes);
- WritableMemory wmem = wh.get();
+ WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
+ WritableMemoryImpl wmem = wh.get();
wh.close();
- //with -ea assert: Memory not valid.
+ //with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
wmem.getLong(0);
}
@@ -337,36 +337,36 @@ public class MemoryTest {
public void checkRegionUseAfterFree() {
int bytes = 64;
@SuppressWarnings("resource") //intentionally not using try-with-resouces here
- WritableHandle wh = WritableMemory.allocateDirect(bytes);
- Memory wmem = wh.get();
- Memory region = wmem.region(0L, bytes);
+ WritableHandle wh = WritableMemoryImpl.allocateDirect(bytes);
+ MemoryImpl wmem = wh.get();
+ MemoryImpl region = wmem.region(0L, bytes);
wh.close();
- //with -ea assert: Memory not valid.
+ //with -ea assert: MemoryImpl not valid.
//with -da sometimes segfaults, sometimes passes!
region.getByte(0);
}
@Test
public void checkUnsafeByteBufferView() {
- try (WritableDirectHandle wmemDirectHandle = WritableMemory.allocateDirect(2)) {
- WritableMemory wmemDirect = wmemDirectHandle.get();
+ try (WritableDirectHandle wmemDirectHandle = WritableMemoryImpl.allocateDirect(2)) {
+ WritableMemoryImpl wmemDirect = wmemDirectHandle.get();
wmemDirect.putByte(0, (byte) 1);
wmemDirect.putByte(1, (byte) 2);
checkUnsafeByteBufferView(wmemDirect);
}
- checkUnsafeByteBufferView(Memory.wrap(new byte[] {1, 2}));
+ checkUnsafeByteBufferView(MemoryImpl.wrap(new byte[] {1, 2}));
try {
@SuppressWarnings("unused")
- ByteBuffer unused = Memory.wrap(new int[]{1}).unsafeByteBufferView(0, 1);
+ ByteBuffer unused = MemoryImpl.wrap(new int[]{1}).unsafeByteBufferView(0, 1);
Assert.fail();
} catch (UnsupportedOperationException ingore) {
// expected
}
}
- private static void checkUnsafeByteBufferView(final Memory mem) {
+ private static void checkUnsafeByteBufferView(final MemoryImpl mem) {
ByteBuffer emptyByteBuffer = mem.unsafeByteBufferView(0, 0);
Assert.assertEquals(emptyByteBuffer.capacity(), 0);
ByteBuffer bb = mem.unsafeByteBufferView(1, 1);
@@ -387,9 +387,9 @@ public class MemoryTest {
@Test
public void checkMonitorDirectStats() {
int bytes = 1024;
- WritableHandle wh1 = WritableMemory.allocateDirect(bytes);
- WritableHandle wh2 = WritableMemory.allocateDirect(bytes);
- WritableMemory wMem2 = wh2.get();
+ WritableHandle wh1 = WritableMemoryImpl.allocateDirect(bytes);
+ WritableHandle wh2 = WritableMemoryImpl.allocateDirect(bytes);
+ WritableMemoryImpl wMem2 = wh2.get();
assertEquals(wMem2.getCurrentDirectMemoryAllocations(), 2L);
assertEquals(wMem2.getCurrentDirectMemoryAllocated(), 2 * bytes);
@@ -410,9 +410,9 @@ public class MemoryTest {
File file = getResourceFile("GettysburgAddress.txt");
long bytes = file.length();
- MapHandle mmh1 = Memory.map(file);
- MapHandle mmh2 = Memory.map(file);
- Memory wmem2 = mmh2.get();
+ MapHandle mmh1 = MemoryImpl.map(file);
+ MapHandle mmh2 = MemoryImpl.map(file);
+ MemoryImpl wmem2 = mmh2.get();
assertEquals(wmem2.getCurrentDirectMemoryMapAllocations(), 2L);
assertEquals(wmem2.getCurrentDirectMemoryMapAllocated(), 2 * bytes);
@@ -430,10 +430,10 @@ public class MemoryTest {
@Test
public void checkNullMemReqSvr() {
- WritableMemory wmem = WritableMemory.writableWrap(new byte[16]);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(new byte[16]);
assertNull(wmem.getMemoryRequestServer());
- try (WritableDirectHandle wdh = WritableMemory.allocateDirect(16)) {
- WritableMemory wmem2 = wdh.get();
+ try (WritableDirectHandle wdh = WritableMemoryImpl.allocateDirect(16)) {
+ WritableMemoryImpl wmem2 = wdh.get();
assertNotNull(wmem2.getMemoryRequestServer());
}
println(wmem.toHexString("Test", 0, 16));
@@ -441,7 +441,7 @@ public class MemoryTest {
@Test
public void checkHashCode() {
- WritableMemory wmem = WritableMemory.allocate(32 + 7);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(32 + 7);
int hc = wmem.hashCode();
assertEquals(hc, -1895166923);
}
@@ -449,7 +449,7 @@ public class MemoryTest {
@Test
public void checkSelfEqualsToAndCompareTo() {
int len = 64;
- WritableMemory wmem = WritableMemory.allocate(len);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(len);
for (int i = 0; i < len; i++) { wmem.putByte(i, (byte) i); }
assertTrue(wmem.equalTo(0, wmem, 0, len));
assertFalse(wmem.equalTo(0, wmem, len/2, len/2));
@@ -461,7 +461,7 @@ public class MemoryTest {
public void wrapBigEndianAsLittle() {
ByteBuffer bb = ByteBuffer.allocate(64);
bb.putChar(0, (char)1); //as BE
- Memory mem = Memory.wrap(bb, ByteOrder.LITTLE_ENDIAN);
+ MemoryImpl mem = MemoryImpl.wrap(bb, ByteOrder.LITTLE_ENDIAN);
assertEquals(mem.getChar(0), 256);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java b/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
index 01f06e0..08e8bf8 100644
--- a/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/MemoryWriteToTest.java
@@ -28,8 +28,8 @@ import java.nio.channels.WritableByteChannel;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -59,8 +59,8 @@ public class MemoryWriteToTest {
@Test
public void testOffHeap() throws IOException {
try (WritableHandle handle =
- WritableMemory.allocateDirect((UNSAFE_COPY_THRESHOLD_BYTES * 5) + 10)) {
- WritableMemory mem = handle.get();
+ WritableMemoryImpl.allocateDirect((UNSAFE_COPY_THRESHOLD_BYTES * 5) + 10)) {
+ WritableMemoryImpl mem = handle.get();
testWriteTo(mem.region(0, 0));
testOffHeap(mem, 7);
testOffHeap(mem, 1023);
@@ -70,28 +70,28 @@ public class MemoryWriteToTest {
}
}
- private static void testOffHeap(WritableMemory mem, int size) throws IOException {
+ private static void testOffHeap(WritableMemoryImpl mem, int size) throws IOException {
createRandomBytesMemory(size).copyTo(0, mem, 0, size);
testWriteTo(mem.region(0, size));
}
- private static Memory createRandomBytesMemory(int size) {
+ private static MemoryImpl createRandomBytesMemory(int size) {
byte[] bytes = new byte[size];
ThreadLocalRandom.current().nextBytes(bytes);
- return Memory.wrap(bytes);
+ return MemoryImpl.wrap(bytes);
}
- private static Memory createRandomIntsMemory(int size) {
+ private static MemoryImpl createRandomIntsMemory(int size) {
int[] ints = ThreadLocalRandom.current().ints(size).toArray();
- return Memory.wrap(ints);
+ return MemoryImpl.wrap(ints);
}
- private static void testWriteTo(Memory mem) throws IOException {
+ private static void testWriteTo(MemoryImpl mem) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (WritableByteChannel out = Channels.newChannel(baos)) {
mem.writeTo(0, mem.getCapacity(), out);
}
byte[] result = baos.toByteArray();
- Assert.assertTrue(mem.equals(Memory.wrap(result)));
+ Assert.assertTrue(mem.equals(MemoryImpl.wrap(result)));
}
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java b/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
index 31c0d3a..8f0d125 100644
--- a/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/NioBitsTest.java
@@ -31,7 +31,7 @@ public class NioBitsTest {
@Test
public void checkVMParams() {
- println("Max Memory: " + ReflectUtil.getMaxDirectByteBufferMemory());
+ println("Max MemoryImpl: " + ReflectUtil.getMaxDirectByteBufferMemory());
println("Page Aligned: " + ReflectUtil.isPageAligned());
println("Page Size: " + ReflectUtil.pageSize());
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
index 199539f..aa22700 100644
--- a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableBufferImplTest.java
@@ -25,7 +25,7 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.internal.Buffer;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -41,7 +41,7 @@ public class NonNativeWritableBufferImplTest {
int m = Character.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
char ch = 'a';
for (int i = 0; i < n; i++) { wbuf.putChar(i * m, ch++); }
@@ -62,7 +62,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getCharArray(cArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putCharArray(cArr, 0, n);
assertEquals(arr2, arr1);
@@ -74,7 +74,7 @@ public class NonNativeWritableBufferImplTest {
int m = Double.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
double dbl = 1.0;
for (int i = 0; i < n; i++) { wbuf.putDouble(i * m, dbl++); }
@@ -95,7 +95,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getDoubleArray(dblArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putDoubleArray(dblArr, 0, n);
assertEquals(arr2, arr1);
@@ -107,7 +107,7 @@ public class NonNativeWritableBufferImplTest {
int m = Float.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
float flt = 1.0F;
for (int i = 0; i < n; i++) { wbuf.putFloat(i * m, flt++); }
@@ -128,7 +128,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getFloatArray(fltArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putFloatArray(fltArr, 0, n);
assertEquals(arr2, arr1);
@@ -140,7 +140,7 @@ public class NonNativeWritableBufferImplTest {
int m = Integer.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
int intg = 1;
for (int i = 0; i < n; i++) { wbuf.putInt(i * m, intg++); }
@@ -161,7 +161,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getIntArray(intArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putIntArray(intArr, 0, n);
assertEquals(arr2, arr1);
@@ -173,7 +173,7 @@ public class NonNativeWritableBufferImplTest {
int m = Long.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
long lng = 1;
for (int i = 0; i < n; i++) { wbuf.putLong(i * m, lng++); }
@@ -194,7 +194,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getLongArray(longArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putLongArray(longArr, 0, n);
assertEquals(arr2, arr1);
@@ -206,7 +206,7 @@ public class NonNativeWritableBufferImplTest {
int m = Short.BYTES;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
short sht = 1;
for (int i = 0; i < n; i++) { wbuf.putShort(i * m, sht++); }
@@ -227,7 +227,7 @@ public class NonNativeWritableBufferImplTest {
wbuf.setPosition(0);
wbuf.getShortArray(shortArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf2 = wmem2.asWritableBuffer();
wbuf2.putShortArray(shortArr, 0, n);
assertEquals(arr2, arr1);
@@ -237,7 +237,7 @@ public class NonNativeWritableBufferImplTest {
@Test
public void checkDuplicate() {
byte[] bArr = new byte[8];
- WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
WritableBuffer wbuf = wmem.asWritableBuffer();
WritableBuffer wdup = wbuf.writableDuplicate();
assertEquals(wdup.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
@@ -249,7 +249,7 @@ public class NonNativeWritableBufferImplTest {
@Test
public void checkDuplicateZeros() {
byte[] bArr = new byte[0];
- WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
Buffer buf = wmem.asBuffer();
Buffer dup = buf.duplicate();
assertEquals(dup.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
diff --git a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
index a71a610..f9e60f6 100644
--- a/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/NonNativeWritableMemoryImplTest.java
@@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.nio.ByteOrder;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -33,7 +33,7 @@ import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class NonNativeWritableMemoryImplTest {
private byte[] bArr = new byte[8];
- private final WritableMemory wmem = WritableMemory.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
+ private final WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bArr, ByteOrder.BIG_ENDIAN);
//Check primitives
@Test
@@ -42,7 +42,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
for (int i = 0; i < n; i++) { wmem1.putChar(i * m, (char) i++); }
for (int i = 0; i < n; i++) {
assertEquals(wmem1.getChar(i * m), (char) i++);
@@ -51,7 +51,7 @@ public class NonNativeWritableMemoryImplTest {
char[] cArr = new char[n]; //native
wmem1.getCharArray(0, cArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putCharArray(0, cArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -62,7 +62,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
double dbl = 1.0;
for (int i = 0; i < n; i++) { wmem1.putDouble(i * m, dbl++); }
dbl = 1.0;
@@ -73,7 +73,7 @@ public class NonNativeWritableMemoryImplTest {
double[] dblArr = new double[n]; //native
wmem1.getDoubleArray(0, dblArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putDoubleArray(0, dblArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -84,7 +84,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
float flt = 1.0F;
for (int i = 0; i < n; i++) { wmem1.putFloat(i * m, flt++); }
flt = 1.0F;
@@ -95,7 +95,7 @@ public class NonNativeWritableMemoryImplTest {
float[] fltArr = new float[n]; //native
wmem1.getFloatArray(0, fltArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putFloatArray(0, fltArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -106,7 +106,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
int intg = 1;
for (int i = 0; i < n; i++) { wmem1.putInt(i * m, intg++); }
intg = 1;
@@ -117,7 +117,7 @@ public class NonNativeWritableMemoryImplTest {
int[] intArr = new int[n]; //native
wmem1.getIntArray(0, intArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putIntArray(0, intArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -128,7 +128,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
long lng = 1;
for (int i = 0; i < n; i++) { wmem1.putLong(i * m, lng++); }
lng = 1;
@@ -139,7 +139,7 @@ public class NonNativeWritableMemoryImplTest {
long[] longArr = new long[n]; //native
wmem1.getLongArray(0, longArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putLongArray(0, longArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -150,7 +150,7 @@ public class NonNativeWritableMemoryImplTest {
int n = ((1 << 20) / m) + m;
byte[] arr1 = new byte[n * m]; //non-native
//put & get
- WritableMemory wmem1 = WritableMemory.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(arr1, ByteOrder.BIG_ENDIAN);
short sht = 1;
for (int i = 0; i < n; i++) { wmem1.putShort(i * m, sht++); }
sht = 1;
@@ -161,7 +161,7 @@ public class NonNativeWritableMemoryImplTest {
short[] shortArr = new short[n]; //native
wmem1.getShortArray(0, shortArr, 0, n); //wmem is non-native
byte[] arr2 = new byte[n * m];
- WritableMemory wmem2 = WritableMemory.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(arr2, ByteOrder.BIG_ENDIAN);
wmem2.putShortArray(0, shortArr, 0, n);
assertEquals(arr2, arr1);
}
@@ -205,15 +205,15 @@ public class NonNativeWritableMemoryImplTest {
//check Region
@Test
public void checkRegion() {
- WritableMemory wreg = wmem.writableRegion(0, wmem.getCapacity());
+ WritableMemoryImpl wreg = wmem.writableRegion(0, wmem.getCapacity());
assertEquals(wreg.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@Test
public void checkRegionZeros() {
byte[] bArr1 = new byte[0];
- WritableMemory wmem1 = WritableMemory.writableWrap(bArr1, ByteOrder.BIG_ENDIAN);
- Memory reg = wmem1.region(0, wmem1.getCapacity());
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(bArr1, ByteOrder.BIG_ENDIAN);
+ MemoryImpl reg = wmem1.region(0, wmem1.getCapacity());
assertEquals(reg.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java b/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
index f1c8794..6436164 100644
--- a/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/SpecificLeafTest.java
@@ -27,9 +27,9 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.apache.datasketches.memory.WritableMapHandle;
import org.apache.datasketches.memory.WritableDirectHandle;
import org.testng.annotations.Test;
@@ -46,14 +46,14 @@ public class SpecificLeafTest {
ByteBuffer bb = ByteBuffer.allocate(bytes);
bb.order(Util.nativeByteOrder);
- Memory mem = Memory.wrap(bb).region(0, bytes, Util.nativeByteOrder);
+ MemoryImpl mem = MemoryImpl.wrap(bb).region(0, bytes, Util.nativeByteOrder);
assertTrue(ReflectUtil.isBBType(mem));
assertTrue(mem.isReadOnly());
checkCrossLeafTypeIds(mem);
Buffer buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
bb.order(Util.nonNativeByteOrder);
- Memory mem2 = Memory.wrap(bb).region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl mem2 = MemoryImpl.wrap(bb).region(0, bytes, Util.nonNativeByteOrder);
Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
Buffer buf3 = buf2.duplicate();
@@ -67,18 +67,18 @@ public class SpecificLeafTest {
@Test
public void checkDirectLeafs() {
int bytes = 128;
- try (WritableDirectHandle h = WritableMemory.allocateDirect(bytes)) {
- WritableMemory wmem = h.get(); //native mem
+ try (WritableDirectHandle h = WritableMemoryImpl.allocateDirect(bytes)) {
+ WritableMemoryImpl wmem = h.get(); //native mem
assertTrue(ReflectUtil.isDirectType(wmem));
assertFalse(wmem.isReadOnly());
checkCrossLeafTypeIds(wmem);
- WritableMemory nnwmem = wmem.writableRegion(0, bytes, Util.nonNativeByteOrder);
+ WritableMemoryImpl nnwmem = wmem.writableRegion(0, bytes, Util.nonNativeByteOrder);
- Memory mem = wmem.region(0, bytes, Util.nativeByteOrder);
+ MemoryImpl mem = wmem.region(0, bytes, Util.nativeByteOrder);
Buffer buf = mem.asBuffer().region(0, bytes, Util.nativeByteOrder);
- Memory mem2 = nnwmem.region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl mem2 = nnwmem.region(0, bytes, Util.nonNativeByteOrder);
Buffer buf2 = mem2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
Buffer buf3 = buf2.duplicate();
@@ -107,18 +107,18 @@ public class SpecificLeafTest {
final long bytes = 128;
- try (WritableMapHandle h = WritableMemory.writableMap(file, 0L, bytes, Util.nativeByteOrder)) {
- WritableMemory mem = h.get(); //native mem
+ try (WritableMapHandle h = WritableMemoryImpl.writableMap(file, 0L, bytes, Util.nativeByteOrder)) {
+ WritableMemoryImpl mem = h.get(); //native mem
assertTrue(ReflectUtil.isMapType(mem));
assertFalse(mem.isReadOnly());
checkCrossLeafTypeIds(mem);
- Memory nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
- Memory reg = mem.region(0, bytes, Util.nativeByteOrder);
+ MemoryImpl reg = mem.region(0, bytes, Util.nativeByteOrder);
Buffer buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
Buffer buf4 = buf.duplicate();
- Memory reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
Buffer buf3 = buf2.duplicate();
@@ -134,17 +134,17 @@ public class SpecificLeafTest {
@Test
public void checkHeapLeafs() {
int bytes = 128;
- Memory mem = Memory.wrap(new byte[bytes]);
+ MemoryImpl mem = MemoryImpl.wrap(new byte[bytes]);
assertTrue(ReflectUtil.isHeapType(mem));
assertTrue(ReflectUtil.isReadOnlyType(mem));
checkCrossLeafTypeIds(mem);
- Memory nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl nnreg = mem.region(0, bytes, Util.nonNativeByteOrder);
- Memory reg = mem.region(0, bytes, Util.nativeByteOrder);
+ MemoryImpl reg = mem.region(0, bytes, Util.nativeByteOrder);
Buffer buf = reg.asBuffer().region(0, bytes, Util.nativeByteOrder);
Buffer buf4 = buf.duplicate();
- Memory reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
+ MemoryImpl reg2 = nnreg.region(0, bytes, Util.nonNativeByteOrder);
Buffer buf2 = reg2.asBuffer().region(0, bytes, Util.nonNativeByteOrder);
Buffer buf3 = buf2.duplicate();
@@ -156,8 +156,8 @@ public class SpecificLeafTest {
assertTrue(ReflectUtil.isDuplicateType(buf4));
}
- private static void checkCrossLeafTypeIds(Memory mem) {
- Memory reg1 = mem.region(0, mem.getCapacity());
+ private static void checkCrossLeafTypeIds(MemoryImpl mem) {
+ MemoryImpl reg1 = mem.region(0, mem.getCapacity());
assertTrue(ReflectUtil.isRegionType(reg1));
Buffer buf1 = reg1.asBuffer();
@@ -169,7 +169,7 @@ public class SpecificLeafTest {
assertTrue(ReflectUtil.isBufferType(buf2));
assertTrue(ReflectUtil.isDuplicateType(buf2));
- Memory mem2 = buf1.asMemory();
+ MemoryImpl mem2 = buf1.asMemory();
assertTrue(ReflectUtil.isRegionType(mem2));
assertFalse(ReflectUtil.isBufferType(mem2));
assertFalse(ReflectUtil.isDuplicateType(mem2));
@@ -180,7 +180,7 @@ public class SpecificLeafTest {
assertTrue(ReflectUtil.isDuplicateType(buf3));
assertTrue(ReflectUtil.isNonNativeType(buf3));
- Memory mem3 = buf3.asMemory();
+ MemoryImpl mem3 = buf3.asMemory();
assertTrue(ReflectUtil.isRegionType(mem3));
assertFalse(ReflectUtil.isBufferType(mem3));
assertFalse(ReflectUtil.isDuplicateType(mem3));
diff --git a/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java b/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
index 2b8b92e..0a710c8 100644
--- a/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
+++ b/src/test/java/org/apache/datasketches/memory/test/Utf8Test.java
@@ -28,9 +28,9 @@ import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Utf8CodingException;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.apache.datasketches.memory.internal.Util.RandomCodePoints;
import org.testng.annotations.Test;
@@ -59,15 +59,15 @@ public class Utf8Test {
@Test
public void testPutInvalidChars() { //The surrogates must be a pair, thus invalid alone
- WritableMemory mem = WritableMemory.allocate(10);
- WritableMemory emptyMem = WritableMemory.allocate(0);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(10);
+ WritableMemoryImpl emptyMem = WritableMemoryImpl.allocate(0);
for (int c = Character.MIN_SURROGATE; c <= Character.MAX_SURROGATE; c++) {
assertSurrogate(mem, (char) c);
assertSurrogate(emptyMem, (char) c);
}
}
- private static void assertSurrogate(WritableMemory mem, char c) {
+ private static void assertSurrogate(WritableMemoryImpl mem, char c) {
try {
mem.putCharsToUtf8(0, new String(new char[] {c}));
fail();
@@ -78,7 +78,7 @@ public class Utf8Test {
@Test
public void testPutInvaidSurrogatePairs() {
- WritableMemory mem = WritableMemory.allocate(4);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(4);
StringBuilder sb = new StringBuilder();
sb.append(Character.MIN_HIGH_SURROGATE);
sb.append(Character.MAX_HIGH_SURROGATE);
@@ -91,7 +91,7 @@ public class Utf8Test {
@Test
public void testPutHighBMP() {
- WritableMemory mem = WritableMemory.allocate(2);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(2);
StringBuilder sb = new StringBuilder();
sb.append("\uE000");
try {
@@ -103,7 +103,7 @@ public class Utf8Test {
@Test
public void testPutExtendedAscii() {
- WritableMemory mem = WritableMemory.allocate(1);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(1);
StringBuilder sb = new StringBuilder();
sb.append("\u07FF");
try {
@@ -115,7 +115,7 @@ public class Utf8Test {
@Test
public void testPutOneAsciiToEmpty() {
- WritableMemory mem = WritableMemory.allocate(0);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(0);
StringBuilder sb = new StringBuilder();
sb.append("a");
try {
@@ -127,7 +127,7 @@ public class Utf8Test {
@Test
public void testPutValidSurrogatePair() {
- WritableMemory mem = WritableMemory.allocate(4);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(4);
StringBuilder sb = new StringBuilder();
sb.append(Character.MIN_HIGH_SURROGATE);
sb.append(Character.MIN_LOW_SURROGATE);
@@ -218,7 +218,7 @@ public class Utf8Test {
rcp.fillCodePointArray(cpArr, 0, minPlane2CP);
String rcpStr = new String(cpArr, 0, numCP);
//println(rcpStr);
- WritableMemory wmem = WritableMemory.allocate(4 * numCP);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(4 * numCP);
int utf8Bytes = (int) wmem.putCharsToUtf8(0, rcpStr);
StringBuilder sb = new StringBuilder();
@@ -302,7 +302,7 @@ public class Utf8Test {
String refStr = "Quizdeltagerne spiste jordb\u00e6r med fl\u00f8de, mens cirkusklovnen";
byte[] refByteArr = refStr.getBytes(UTF_8);
int addBytes = refByteArr.length;
- WritableMemory refMem = WritableMemory.writableWrap(refByteArr);
+ WritableMemoryImpl refMem = WritableMemoryImpl.writableWrap(refByteArr);
int decodedChars = refMem.getCharsFromUtf8(0, addBytes, sb);
String finalStr = sb.toString();
int finalChars = finalStr.toCharArray().length;
@@ -318,7 +318,7 @@ public class Utf8Test {
byte[] refByteArr = refStr.getBytes(UTF_8);
int refBytes = refByteArr.length;
int offset = 100;
- WritableMemory tgtMem = WritableMemory.allocate(refBytes + offset);
+ WritableMemoryImpl tgtMem = WritableMemoryImpl.allocate(refBytes + offset);
long bytesEncoded = tgtMem.putCharsToUtf8(offset, refStr);
assertEquals(bytesEncoded, refBytes);
}
@@ -370,7 +370,7 @@ public class Utf8Test {
}
@Test
- public void testInvalidBufferSlice() { //these are pure Memory bounds violations
+ public void testInvalidBufferSlice() { //these are pure MemoryImpl bounds violations
byte[] bytes = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
assertInvalidSlice(bytes, bytes.length - 3, 4);
assertInvalidSlice(bytes, bytes.length, 1);
@@ -389,14 +389,14 @@ public class Utf8Test {
private static void assertInvalid(byte[] bytes) {
int bytesLen = bytes.length;
try {
- Memory.wrap(bytes).getCharsFromUtf8(0, bytesLen, new StringBuilder());
+ MemoryImpl.wrap(bytes).getCharsFromUtf8(0, bytesLen, new StringBuilder());
fail();
} catch (Utf8CodingException e) {
// Expected.
}
try {
CharBuffer cb = CharBuffer.allocate(bytesLen);
- Memory.wrap(bytes).getCharsFromUtf8(0, bytesLen, cb);
+ MemoryImpl.wrap(bytes).getCharsFromUtf8(0, bytesLen, cb);
fail();
} catch (Utf8CodingException | IOException e) {
// Expected.
@@ -405,7 +405,7 @@ public class Utf8Test {
private static void assertInvalidSlice(byte[] bytes, int index, int size) {
try {
- Memory mem = Memory.wrap(bytes);
+ MemoryImpl mem = MemoryImpl.wrap(bytes);
mem.getCharsFromUtf8(index, size, new StringBuilder());
fail();
} catch (IllegalArgumentException e) { //Pure bounds violation
@@ -436,17 +436,17 @@ public class Utf8Test {
if (utf8LengthBytes == -1) {
utf8LengthBytes = refByteArr.length;
}
- Memory refMem = Memory.wrap(refByteArr);
+ MemoryImpl refMem = MemoryImpl.wrap(refByteArr);
byte[] refByteArr2 = new byte[refByteArr.length + 1];
System.arraycopy(refByteArr, 0, refByteArr2, 1, refByteArr.length);
- Memory refReg = Memory.wrap(refByteArr2).region(1, refByteArr.length);
+ MemoryImpl refReg = MemoryImpl.wrap(refByteArr2).region(1, refByteArr.length);
- WritableMemory dstMem = WritableMemory.allocate(refByteArr.length);
- WritableMemory dstMem2 =
- WritableMemory.allocate(refByteArr.length + 1).writableRegion(1, refByteArr.length);
+ WritableMemoryImpl dstMem = WritableMemoryImpl.allocate(refByteArr.length);
+ WritableMemoryImpl dstMem2 =
+ WritableMemoryImpl.allocate(refByteArr.length + 1).writableRegion(1, refByteArr.length);
- // Test with Memory objects, where base offset != 0
+ // Test with MemoryImpl objects, where base offset != 0
assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refMem, dstMem);
assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refMem, dstMem2);
assertRoundTrips(refStr, refSubCharLen, offsetBytes, utf8LengthBytes, refByteArr, refReg, dstMem);
@@ -454,7 +454,7 @@ public class Utf8Test {
}
private static void assertRoundTrips(String refStr, int refSubCharLen, int offsetBytes,
- int utf8LengthBytes, byte[] refByteArr, Memory refMem, WritableMemory dstMem)
+ int utf8LengthBytes, byte[] refByteArr, MemoryImpl refMem, WritableMemoryImpl dstMem)
throws IOException {
StringBuilder sb = new StringBuilder();
@@ -476,7 +476,7 @@ public class Utf8Test {
assertEquals(0, dstMem.compareTo(0, refByteArr.length, refMem, 0, refByteArr.length));
// Test write overflow
- WritableMemory writeMem2 = WritableMemory.allocate(refByteArr.length - 1);
+ WritableMemoryImpl writeMem2 = WritableMemoryImpl.allocate(refByteArr.length - 1);
try {
writeMem2.putCharsToUtf8(0, refStr);
fail();
diff --git a/src/test/java/org/apache/datasketches/memory/test/UtilTest.java b/src/test/java/org/apache/datasketches/memory/test/UtilTest.java
index 83228bf..fbc2962 100644
--- a/src/test/java/org/apache/datasketches/memory/test/UtilTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/UtilTest.java
@@ -44,7 +44,7 @@ import java.nio.file.attribute.PosixFilePermissions;
import org.apache.datasketches.memory.internal.UnsafeUtil;
import org.apache.datasketches.memory.internal.Util;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -55,7 +55,7 @@ public class UtilTest {
@Test
public void checkBinarySearch() {
int k = 1024; //longs
- WritableMemory wMem = WritableMemory.allocate(k << 3); //1024 longs
+ WritableMemoryImpl wMem = WritableMemoryImpl.allocate(k << 3); //1024 longs
for (int i = 0; i < k; i++) { wMem.putLong(i << 3, i); }
long idx = Util.binarySearchLongs(wMem, 0, k - 1, k / 2);
long val = wMem.getLong(idx << 3);
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
index 99dfd13..7593be8 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableBufferImplTest.java
@@ -28,12 +28,12 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.UnsafeUtil;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -46,8 +46,8 @@ public class WritableBufferImplTest {
@Test
public void checkNativeCapacityAndClose() {
int memCapacity = 64;
- WritableHandle wmh = WritableMemory.allocateDirect(memCapacity);
- WritableMemory wmem = wmh.get();
+ WritableHandle wmh = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableMemoryImpl wmem = wmh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
assertEquals(wbuf.getCapacity(), memCapacity);
@@ -64,13 +64,13 @@ public class WritableBufferImplTest {
boolean[] srcArray = { true, false, true, false, false, true, true, false };
boolean[] dstArray = new boolean[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getBooleanArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getBooleanArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -83,13 +83,13 @@ public class WritableBufferImplTest {
byte[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
byte[] dstArray = new byte[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getByteArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getByteArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -101,13 +101,13 @@ public class WritableBufferImplTest {
char[] srcArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
char[] dstArray = new char[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getCharArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getCharArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -119,13 +119,13 @@ public class WritableBufferImplTest {
short[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
short[] dstArray = new short[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getShortArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getShortArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -137,13 +137,13 @@ public class WritableBufferImplTest {
int[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
int[] dstArray = new int[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getIntArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getIntArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -155,13 +155,13 @@ public class WritableBufferImplTest {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
long[] dstArray = new long[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getLongArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getLongArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -173,13 +173,13 @@ public class WritableBufferImplTest {
float[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
float[] dstArray = new float[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getFloatArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getFloatArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -191,13 +191,13 @@ public class WritableBufferImplTest {
double[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
double[] dstArray = new double[8];
- Buffer buf = Memory.wrap(srcArray).asBuffer();
+ Buffer buf = MemoryImpl.wrap(srcArray).asBuffer();
buf.getDoubleArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
wbuf.getDoubleArray(dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -207,8 +207,8 @@ public class WritableBufferImplTest {
@Test
public void checkNativeBaseBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory wmem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl wmem = wrh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
wbuf.toHexString("Force Assertion Error", memCapacity, 8);
} catch (IllegalArgumentException e) {
@@ -219,8 +219,8 @@ public class WritableBufferImplTest {
@Test
public void checkNativeSrcArrayBound() {
long memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory wmem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl wmem = wrh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
byte[] srcArray = { 1, -2, 3, -4 };
wbuf.putByteArray(srcArray, 0, 5); //wrong!
@@ -233,8 +233,8 @@ public class WritableBufferImplTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkRegionBounds() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory wmem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl wmem = wrh.get();
WritableBuffer wbuf = wmem.asWritableBuffer();
wbuf.writableRegion(1, 64, wbuf.getTypeByteOrder()); //wrong!
}
@@ -344,10 +344,10 @@ public class WritableBufferImplTest {
@Test
public void checkIsDirect() {
int memCapacity = 64;
- WritableBuffer mem = WritableMemory.allocate(memCapacity).asWritableBuffer();
+ WritableBuffer mem = WritableMemoryImpl.allocate(memCapacity).asWritableBuffer();
assertFalse(mem.isDirect());
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem2 = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem2 = wrh.get();
WritableBuffer wbuf = mem2.asWritableBuffer();
assertTrue(wbuf.isDirect());
wrh.close();
@@ -358,7 +358,7 @@ public class WritableBufferImplTest {
public void checkIsReadOnly() {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
- WritableBuffer wbuf = WritableMemory.writableWrap(srcArray).asWritableBuffer();
+ WritableBuffer wbuf = WritableMemoryImpl.writableWrap(srcArray).asWritableBuffer();
assertFalse(wbuf.isReadOnly());
Buffer buf = wbuf;
@@ -380,9 +380,9 @@ public class WritableBufferImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- Buffer buf1 = Memory.wrap(arr1).asBuffer();
- Buffer buf2 = Memory.wrap(arr2).asBuffer();
- Buffer buf3 = Memory.wrap(arr3).asBuffer();
+ Buffer buf1 = MemoryImpl.wrap(arr1).asBuffer();
+ Buffer buf2 = MemoryImpl.wrap(arr2).asBuffer();
+ Buffer buf3 = MemoryImpl.wrap(arr3).asBuffer();
int comp = buf1.compareTo(0, 3, buf2, 0, 3);
assertEquals(comp, 0);
@@ -403,17 +403,17 @@ public class WritableBufferImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- try (WritableHandle h1 = WritableMemory.allocateDirect(4);
- WritableHandle h2 = WritableMemory.allocateDirect(4);
- WritableHandle h3 = WritableMemory.allocateDirect(5))
+ try (WritableHandle h1 = WritableMemoryImpl.allocateDirect(4);
+ WritableHandle h2 = WritableMemoryImpl.allocateDirect(4);
+ WritableHandle h3 = WritableMemoryImpl.allocateDirect(5))
{
- WritableMemory mem1 = h1.get();
+ WritableMemoryImpl mem1 = h1.get();
mem1.putByteArray(0, arr1, 0, 4);
- WritableMemory mem2 = h2.get();
+ WritableMemoryImpl mem2 = h2.get();
mem2.putByteArray(0, arr2, 0, 4);
- WritableMemory mem3 = h3.get();
+ WritableMemoryImpl mem3 = h3.get();
mem3.putByteArray(0, arr3, 0, 5);
Buffer buf1 = mem1.asBuffer();
@@ -436,7 +436,7 @@ public class WritableBufferImplTest {
@Test
public void checkAsBuffer() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
WritableBuffer wbuf = wmem.asWritableBuffer();
wbuf.setPosition(32);
for (int i = 32; i < 64; i++) { wbuf.putByte((byte)i); }
@@ -451,7 +451,7 @@ public class WritableBufferImplTest {
@Test
public void checkDuplicate() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
for (int i = 0; i < 64; i++) { wmem.putByte(i, (byte)i); }
WritableBuffer wbuf = wmem.asWritableBuffer().writableDuplicate();
@@ -464,18 +464,18 @@ public class WritableBufferImplTest {
assertEquals(buf.getByte(), i);
}
- WritableMemory wmem2 = wbuf.asWritableMemory();
+ WritableMemoryImpl wmem2 = wbuf.asWritableMemory();
for (int i = 0; i < 64; i++) {
assertEquals(wmem2.getByte(i), i);
}
- WritableMemory wmem3 = wbuf.asWritableMemory();
+ WritableMemoryImpl wmem3 = wbuf.asWritableMemory();
wmem3.checkValidAndBounds(0, 64);
}
@Test
public void checkCumAndRegionOffset() {
- WritableMemory wmem = WritableMemory.allocate(64);
- WritableMemory reg = wmem.writableRegion(32, 32);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
+ WritableMemoryImpl reg = wmem.writableRegion(32, 32);
WritableBuffer buf = reg.asWritableBuffer();
assertEquals(buf.getRegionOffset(), 32);
assertEquals(buf.getRegionOffset(0), 32);
@@ -486,14 +486,14 @@ public class WritableBufferImplTest {
@Test
public void checkIsSameResource() {
byte[] byteArr = new byte[64];
- WritableBuffer wbuf1 = WritableMemory.writableWrap(byteArr).asWritableBuffer();
- WritableBuffer wbuf2 = WritableMemory.writableWrap(byteArr).asWritableBuffer();
+ WritableBuffer wbuf1 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
+ WritableBuffer wbuf2 = WritableMemoryImpl.writableWrap(byteArr).asWritableBuffer();
assertTrue(wbuf1.isSameResource(wbuf2));
}
@Test
public void checkDegenerateRegionReturn() {
- Memory mem = Memory.wrap(new byte[0]);
+ MemoryImpl mem = MemoryImpl.wrap(new byte[0]);
Buffer buf = mem.asBuffer();
Buffer reg = buf.region();
assertEquals(reg.getCapacity(), 0);
@@ -504,13 +504,13 @@ public class WritableBufferImplTest {
ByteBuffer bb = ByteBuffer.allocate(64);
WritableBuffer wbuf = WritableBuffer.wrap(bb);
@SuppressWarnings("unused")
- WritableMemory wmem = wbuf.asWritableMemory();
+ WritableMemoryImpl wmem = wbuf.asWritableMemory();
try {
Buffer buf = Buffer.wrap(bb);
wbuf = (WritableBuffer) buf;
@SuppressWarnings("unused")
- WritableMemory wmem2 = wbuf.asWritableMemory();
+ WritableMemoryImpl wmem2 = wbuf.asWritableMemory();
Assert.fail();
} catch (ReadOnlyException expected) {
// expected
@@ -573,7 +573,7 @@ public class WritableBufferImplTest {
@Test
public void checkZeroBuffer() {
- WritableMemory wmem = WritableMemory.allocate(8);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(8);
WritableBuffer wbuf = wmem.asWritableBuffer();
WritableBuffer reg = wbuf.writableRegion(0, 0, wbuf.getTypeByteOrder());
assertEquals(reg.getCapacity(), 0);
@@ -581,7 +581,7 @@ public class WritableBufferImplTest {
@Test
public void checkDuplicateNonNative() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
wmem.putShort(0, (short) 1);
Buffer buf = wmem.asWritableBuffer().duplicate(Util.nonNativeByteOrder);
assertEquals(buf.getShort(0), 256);
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
index cd3e7ad..d29dff3 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableDirectCopyTest.java
@@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -39,8 +39,8 @@ public class WritableDirectCopyTest {
public void checkCopyWithinNativeSmall() {
int memCapacity = 64;
int half = memCapacity / 2;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.clear();
for (int i = 0; i < half; i++) { //fill first half
@@ -61,8 +61,8 @@ public class WritableDirectCopyTest {
int memCapLongs = memCapacity / 8;
int halfBytes = memCapacity / 2;
int halfLongs = memCapLongs / 2;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.clear();
for (int i = 0; i < halfLongs; i++) {
@@ -80,8 +80,8 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeOverlap() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.clear();
//println(mem.toHexString("Clear 64", 0, memCapacity));
@@ -96,8 +96,8 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeSrcBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.copyTo(32, mem, 32, 33); //hit source bound check
fail("Did Not Catch Assertion Error: source bound");
} catch (IllegalArgumentException e) {
@@ -108,8 +108,8 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyWithinNativeDstBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.copyTo(0, mem, 32, 33); //hit dst bound check
fail("Did Not Catch Assertion Error: dst bound");
} catch (IllegalArgumentException e) {
@@ -121,10 +121,10 @@ public class WritableDirectCopyTest {
public void checkCopyCrossNativeSmall() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity);
- WritableHandle wrh2 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
- WritableMemory mem2 = wrh2.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableHandle wrh2 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
+ WritableMemoryImpl mem2 = wrh2.get();
for (int i = 0; i < memCapacity; i++) {
mem1.putByte(i, (byte) i);
@@ -145,10 +145,10 @@ public class WritableDirectCopyTest {
int memCapacity = (2 << 20) + 64;
int memCapLongs = memCapacity / 8;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity);
- WritableHandle wrh2 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
- WritableMemory mem2 = wrh2.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableHandle wrh2 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
+ WritableMemoryImpl mem2 = wrh2.get();
for (int i = 0; i < memCapLongs; i++) {
mem1.putLong(i * 8, i);
@@ -166,14 +166,14 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyCrossNativeAndByteArray() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
- WritableMemory mem2 = WritableMemory.allocate(memCapacity);
+ WritableMemoryImpl mem2 = WritableMemoryImpl.allocate(memCapacity);
mem1.copyTo(8, mem2, 16, 16);
for (int i = 0; i < 16; i++) {
@@ -187,18 +187,18 @@ public class WritableDirectCopyTest {
public void checkCopyCrossRegionsSameNative() {
int memCapacity = 128;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i = 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
//println(mem1.toHexString("Mem1", 0, (int)mem1.getCapacity()));
- Memory reg1 = mem1.region(8, 16);
+ MemoryImpl reg1 = mem1.region(8, 16);
//println(reg1.toHexString("Reg1", 0, (int)reg1.getCapacity()));
- WritableMemory reg2 = mem1.writableRegion(24, 16);
+ WritableMemoryImpl reg2 = mem1.writableRegion(24, 16);
//println(reg2.toHexString("Reg2", 0, (int)reg2.getCapacity()));
reg1.copyTo(0, reg2, 0, 16);
@@ -213,22 +213,22 @@ public class WritableDirectCopyTest {
@Test
public void checkCopyCrossNativeArrayAndHierarchicalRegions() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i = 0; i < mem1.getCapacity(); i++) { //fill with numbers
mem1.putByte(i, (byte) i);
}
//println(mem1.toHexString("Mem1", 0, (int)mem1.getCapacity()));
- WritableMemory mem2 = WritableMemory.allocate(memCapacity);
+ WritableMemoryImpl mem2 = WritableMemoryImpl.allocate(memCapacity);
- Memory reg1 = mem1.region(8, 32);
- Memory reg1B = reg1.region(8, 16);
+ MemoryImpl reg1 = mem1.region(8, 32);
+ MemoryImpl reg1B = reg1.region(8, 16);
//println(reg1.toHexString("Reg1", 0, (int)reg1.getCapacity()));
//println(reg1B.toHexString("Reg1B", 0, (int)reg1B.getCapacity()));
- WritableMemory reg2 = mem2.writableRegion(32, 16);
+ WritableMemoryImpl reg2 = mem2.writableRegion(32, 16);
reg1B.copyTo(0, reg2, 0, 16);
//println(reg2.toHexString("Reg2", 0, (int)reg2.getCapacity()));
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
index 78ba991..ccf994e 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryImplTest.java
@@ -29,12 +29,12 @@ import java.nio.ByteOrder;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.internal.Buffer;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.ReadOnlyException;
import org.apache.datasketches.memory.internal.UnsafeUtil;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -46,8 +46,8 @@ public class WritableMemoryImplTest {
@Test
public void checkNativeCapacityAndClose() {
int memCapacity = 64;
- WritableHandle wmh = WritableMemory.allocateDirect(memCapacity);
- WritableMemory mem = wmh.get();
+ WritableHandle wmh = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableMemoryImpl mem = wmh.get();
assertEquals(memCapacity, mem.getCapacity());
wmh.close(); //intentional
@@ -63,13 +63,13 @@ public class WritableMemoryImplTest {
boolean[] srcArray = { true, false, true, false, false, true, true, false };
boolean[] dstArray = new boolean[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getBooleanArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getBooleanArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -82,13 +82,13 @@ public class WritableMemoryImplTest {
byte[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
byte[] dstArray = new byte[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getByteArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getByteArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -100,13 +100,13 @@ public class WritableMemoryImplTest {
char[] srcArray = { 1, 2, 3, 4, 5, 6, 7, 8 };
char[] dstArray = new char[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getCharArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getCharArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -118,13 +118,13 @@ public class WritableMemoryImplTest {
short[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
short[] dstArray = new short[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getShortArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getShortArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -136,13 +136,13 @@ public class WritableMemoryImplTest {
int[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
int[] dstArray = new int[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getIntArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getIntArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -154,13 +154,13 @@ public class WritableMemoryImplTest {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
long[] dstArray = new long[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getLongArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getLongArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -172,13 +172,13 @@ public class WritableMemoryImplTest {
float[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
float[] dstArray = new float[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getFloatArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getFloatArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -190,13 +190,13 @@ public class WritableMemoryImplTest {
double[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
double[] dstArray = new double[8];
- Memory mem = Memory.wrap(srcArray);
+ MemoryImpl mem = MemoryImpl.wrap(srcArray);
mem.getDoubleArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
wmem.getDoubleArray(0, dstArray, 0, 8);
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
@@ -206,8 +206,8 @@ public class WritableMemoryImplTest {
@Test
public void checkNativeBaseBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.toHexString("Force Assertion Error", memCapacity, 8);
} catch (IllegalArgumentException e) {
//ok
@@ -217,8 +217,8 @@ public class WritableMemoryImplTest {
@Test
public void checkNativeSrcArrayBound() {
long memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
byte[] srcArray = { 1, -2, 3, -4 };
mem.putByteArray(0L, srcArray, 0, 5);
} catch (IllegalArgumentException e) {
@@ -230,7 +230,7 @@ public class WritableMemoryImplTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkDegenerateCopyTo() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
wmem.copyTo(0, wmem, 0, 64);
}
@@ -238,8 +238,8 @@ public class WritableMemoryImplTest {
public void checkCopyWithinNativeSmall() {
int memCapacity = 64;
int half = memCapacity/2;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.clear();
for (int i=0; i<half; i++) { //fill first half
@@ -260,8 +260,8 @@ public class WritableMemoryImplTest {
int memCapLongs = memCapacity / 8;
int halfBytes = memCapacity / 2;
int halfLongs = memCapLongs / 2;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.clear();
for (int i=0; i < halfLongs; i++) {
@@ -279,8 +279,8 @@ public class WritableMemoryImplTest {
@Test
public void checkCopyWithinNativeSrcBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.copyTo(32, mem, 32, 33); //hit source bound check
fail("Did Not Catch Assertion Error: source bound");
}
@@ -292,8 +292,8 @@ public class WritableMemoryImplTest {
@Test
public void checkCopyWithinNativeDstBound() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.copyTo(0, mem, 32, 33); //hit dst bound check
fail("Did Not Catch Assertion Error: dst bound");
}
@@ -306,11 +306,11 @@ public class WritableMemoryImplTest {
public void checkCopyCrossNativeSmall() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity);
- WritableHandle wrh2 = WritableMemory.allocateDirect(memCapacity))
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableHandle wrh2 = WritableMemoryImpl.allocateDirect(memCapacity))
{
- WritableMemory mem1 = wrh1.get();
- WritableMemory mem2 = wrh2.get();
+ WritableMemoryImpl mem1 = wrh1.get();
+ WritableMemoryImpl mem2 = wrh2.get();
for (int i=0; i < memCapacity; i++) {
mem1.putByte(i, (byte) i);
@@ -331,11 +331,11 @@ public class WritableMemoryImplTest {
int memCapacity = (2<<20) + 64;
int memCapLongs = memCapacity / 8;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity);
- WritableHandle wrh2 = WritableMemory.allocateDirect(memCapacity))
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity);
+ WritableHandle wrh2 = WritableMemoryImpl.allocateDirect(memCapacity))
{
- WritableMemory mem1 = wrh1.get();
- WritableMemory mem2 = wrh2.get();
+ WritableMemoryImpl mem1 = wrh1.get();
+ WritableMemoryImpl mem2 = wrh2.get();
for (int i=0; i < memCapLongs; i++) {
mem1.putLong(i*8, i);
@@ -353,14 +353,14 @@ public class WritableMemoryImplTest {
@Test
public void checkCopyCrossNativeAndByteArray() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i= 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
- WritableMemory mem2 = WritableMemory.allocate(memCapacity);
+ WritableMemoryImpl mem2 = WritableMemoryImpl.allocate(memCapacity);
mem1.copyTo(8, mem2, 16, 16);
for (int i=0; i<16; i++) {
@@ -374,18 +374,18 @@ public class WritableMemoryImplTest {
public void checkCopyCrossRegionsSameNative() {
int memCapacity = 128;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i= 0; i < mem1.getCapacity(); i++) {
mem1.putByte(i, (byte) i);
}
//println(mem1.toHexString("Mem1", 0, (int)mem1.getCapacity()));
- Memory reg1 = mem1.region(8, 16);
+ MemoryImpl reg1 = mem1.region(8, 16);
//println(reg1.toHexString("Reg1", 0, (int)reg1.getCapacity()));
- WritableMemory reg2 = mem1.writableRegion(24, 16);
+ WritableMemoryImpl reg2 = mem1.writableRegion(24, 16);
//println(reg2.toHexString("Reg2", 0, (int)reg2.getCapacity()));
reg1.copyTo(0, reg2, 0, 16);
@@ -400,22 +400,22 @@ public class WritableMemoryImplTest {
@Test
public void checkCopyCrossNativeArrayAndHierarchicalRegions() {
int memCapacity = 64;
- try (WritableHandle wrh1 = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem1 = wrh1.get();
+ try (WritableHandle wrh1 = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem1 = wrh1.get();
for (int i= 0; i < mem1.getCapacity(); i++) { //fill with numbers
mem1.putByte(i, (byte) i);
}
//println(mem1.toHexString("Mem1", 0, (int)mem1.getCapacity()));
- WritableMemory mem2 = WritableMemory.allocate(memCapacity);
+ WritableMemoryImpl mem2 = WritableMemoryImpl.allocate(memCapacity);
- Memory reg1 = mem1.region(8, 32);
- Memory reg1B = reg1.region(8, 16);
+ MemoryImpl reg1 = mem1.region(8, 32);
+ MemoryImpl reg1B = reg1.region(8, 16);
//println(reg1.toHexString("Reg1", 0, (int)reg1.getCapacity()));
//println(reg1B.toHexString("Reg1B", 0, (int)reg1B.getCapacity()));
- WritableMemory reg2 = mem2.writableRegion(32, 16);
+ WritableMemoryImpl reg2 = mem2.writableRegion(32, 16);
reg1B.copyTo(0, reg2, 0, 16);
//println(reg2.toHexString("Reg2", 0, (int)reg2.getCapacity()));
@@ -430,8 +430,8 @@ public class WritableMemoryImplTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkRegionBounds() {
int memCapacity = 64;
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
- WritableMemory mem = wrh.get();
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
+ WritableMemoryImpl mem = wrh.get();
mem.writableRegion(1, 64);
}
}
@@ -446,7 +446,7 @@ public class WritableMemoryImplTest {
byteBuf.put(i, (byte) i);
}
- WritableMemory wmem = WritableMemory.writableWrap(byteBuf);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteBuf);
for (int i=0; i<memCapacity; i++) {
assertEquals(wmem.getByte(i), byteBuf.get(i));
@@ -468,7 +468,7 @@ public class WritableMemoryImplTest {
byteBuf.put(i, (byte) i);
}
- Memory mem = WritableMemory.writableWrap(byteBuf);
+ MemoryImpl mem = WritableMemoryImpl.writableWrap(byteBuf);
for (int i = 0; i < memCapacity; i++) {
assertEquals(mem.getByte(i), byteBuf.get(i));
@@ -484,7 +484,7 @@ public class WritableMemoryImplTest {
byteBuf.order(ByteOrder.nativeOrder());
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
- WritableMemory.writableWrap(byteBufRO);
+ WritableMemoryImpl.writableWrap(byteBufRO);
}
@Test
@@ -499,7 +499,7 @@ public class WritableMemoryImplTest {
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
byteBufRO.order(ByteOrder.nativeOrder());
- Memory mem = Memory.wrap(byteBufRO);
+ MemoryImpl mem = MemoryImpl.wrap(byteBufRO);
for (int i = 0; i < memCapacity; i++) {
assertEquals(mem.getByte(i), byteBuf.get(i));
@@ -515,7 +515,7 @@ public class WritableMemoryImplTest {
ByteBuffer byteBufRO = byteBuf.asReadOnlyBuffer();
byteBufRO.order(ByteOrder.nativeOrder());
- WritableMemory.writableWrap(byteBufRO);
+ WritableMemoryImpl.writableWrap(byteBufRO);
}
@Test
@@ -528,7 +528,7 @@ public class WritableMemoryImplTest {
byteBuf.put(i, (byte) i);
}
- Memory mem = Memory.wrap(byteBuf);
+ MemoryImpl mem = MemoryImpl.wrap(byteBuf);
for (int i=0; i<memCapacity; i++) {
assertEquals(mem.getByte(i), byteBuf.get(i));
@@ -540,9 +540,9 @@ public class WritableMemoryImplTest {
@Test
public void checkIsDirect() {
int memCapacity = 64;
- WritableMemory mem = WritableMemory.allocate(memCapacity);
+ WritableMemoryImpl mem = WritableMemoryImpl.allocate(memCapacity);
assertFalse(mem.isDirect());
- try (WritableHandle wrh = WritableMemory.allocateDirect(memCapacity)) {
+ try (WritableHandle wrh = WritableMemoryImpl.allocateDirect(memCapacity)) {
mem = wrh.get();
assertTrue(mem.isDirect());
wrh.close();
@@ -553,10 +553,10 @@ public class WritableMemoryImplTest {
public void checkIsReadOnly() {
long[] srcArray = { 1, -2, 3, -4, 5, -6, 7, -8 };
- WritableMemory wmem = WritableMemory.writableWrap(srcArray);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcArray);
assertFalse(wmem.isReadOnly());
- Memory memRO = wmem;
+ MemoryImpl memRO = wmem;
assertFalse(memRO.isReadOnly());
for (int i = 0; i < wmem.getCapacity(); i++) {
@@ -575,10 +575,10 @@ public class WritableMemoryImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- Memory mem1 = Memory.wrap(arr1);
- Memory mem2 = Memory.wrap(arr2);
- Memory mem3 = Memory.wrap(arr3);
- Memory mem4 = Memory.wrap(arr3); //same resource
+ MemoryImpl mem1 = MemoryImpl.wrap(arr1);
+ MemoryImpl mem2 = MemoryImpl.wrap(arr2);
+ MemoryImpl mem3 = MemoryImpl.wrap(arr3);
+ MemoryImpl mem4 = MemoryImpl.wrap(arr3); //same resource
int comp = mem1.compareTo(0, 3, mem2, 0, 3);
assertEquals(comp, 0);
@@ -604,17 +604,17 @@ public class WritableMemoryImplTest {
byte[] arr2 = new byte[] {0, 1, 2, 4};
byte[] arr3 = new byte[] {0, 1, 2, 3, 4};
- try (WritableHandle h1 = WritableMemory.allocateDirect(4);
- WritableHandle h2 = WritableMemory.allocateDirect(4);
- WritableHandle h3 = WritableMemory.allocateDirect(5))
+ try (WritableHandle h1 = WritableMemoryImpl.allocateDirect(4);
+ WritableHandle h2 = WritableMemoryImpl.allocateDirect(4);
+ WritableHandle h3 = WritableMemoryImpl.allocateDirect(5))
{
- WritableMemory mem1 = h1.get();
+ WritableMemoryImpl mem1 = h1.get();
mem1.putByteArray(0, arr1, 0, 4);
- WritableMemory mem2 = h2.get();
+ WritableMemoryImpl mem2 = h2.get();
mem2.putByteArray(0, arr2, 0, 4);
- WritableMemory mem3 = h3.get();
+ WritableMemoryImpl mem3 = h3.get();
mem3.putByteArray(0, arr3, 0, 5);
int comp = mem1.compareTo(0, 3, mem2, 0, 3);
@@ -633,7 +633,7 @@ public class WritableMemoryImplTest {
@Test
public void testCompareToSameStart() {
- Memory mem = WritableMemory.allocate(3);
+ MemoryImpl mem = WritableMemoryImpl.allocate(3);
assertEquals(-1, mem.compareTo(0, 1, mem, 0, 2));
assertEquals(0, mem.compareTo(1, 1, mem, 1, 1));
assertEquals(1, mem.compareTo(1, 2, mem, 1, 1));
@@ -641,7 +641,7 @@ public class WritableMemoryImplTest {
@Test
public void checkAsBuffer() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
WritableBuffer wbuf = wmem.asWritableBuffer();
wbuf.setPosition(32);
for (int i = 32; i < 64; i++) { wbuf.putByte((byte)i); }
@@ -656,8 +656,8 @@ public class WritableMemoryImplTest {
@Test
public void checkCumAndRegionOffset() {
- WritableMemory wmem = WritableMemory.allocate(64);
- WritableMemory reg = wmem.writableRegion(32, 32);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
+ WritableMemoryImpl reg = wmem.writableRegion(32, 32);
assertEquals(reg.getRegionOffset(), 32);
assertEquals(reg.getRegionOffset(0), 32);
assertEquals(reg.getCumulativeOffset(), 32 + 16);
@@ -667,8 +667,8 @@ public class WritableMemoryImplTest {
@Test
public void checkIsSameResource() {
byte[] byteArr = new byte[64];
- WritableMemory wmem1 = WritableMemory.writableWrap(byteArr);
- WritableMemory wmem2 = WritableMemory.writableWrap(byteArr);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.writableWrap(byteArr);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.writableWrap(byteArr);
assertTrue(wmem1.isSameResource(wmem2));
}
@@ -677,7 +677,7 @@ public class WritableMemoryImplTest {
ByteBuffer byteBuf = ByteBuffer.allocate(64);
byteBuf.position(16);
byteBuf.limit(48);
- WritableMemory wmem = WritableMemory.writableWrap(byteBuf);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteBuf);
WritableBuffer wbuf = wmem.asWritableBuffer();
assertEquals(wbuf.getCapacity(), 64);
assertEquals(wbuf.getPosition(), 0);
@@ -687,26 +687,26 @@ public class WritableMemoryImplTest {
@Test(expectedExceptions = ReadOnlyException.class)
public void checkAsWritableRegionRO() {
ByteBuffer byteBuf = ByteBuffer.allocate(64);
- WritableMemory wmem = (WritableMemory) Memory.wrap(byteBuf);
+ WritableMemoryImpl wmem = (WritableMemoryImpl) MemoryImpl.wrap(byteBuf);
wmem.writableRegion(0, 1);
}
@Test(expectedExceptions = ReadOnlyException.class)
public void checkAsWritableBufferRO() {
ByteBuffer byteBuf = ByteBuffer.allocate(64);
- WritableMemory wmem = (WritableMemory) Memory.wrap(byteBuf);
+ WritableMemoryImpl wmem = (WritableMemoryImpl) MemoryImpl.wrap(byteBuf);
wmem.asWritableBuffer();
}
@Test void checkZeroMemory() {
- WritableMemory wmem = WritableMemory.allocate(8);
- WritableMemory reg = wmem.writableRegion(0, 0);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(8);
+ WritableMemoryImpl reg = wmem.writableRegion(0, 0);
assertEquals(reg.getCapacity(), 0);
}
@Test
public void checkAsBufferNonNative() {
- WritableMemory wmem = WritableMemory.allocate(64);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64);
wmem.putShort(0, (short) 1);
Buffer buf = wmem.asBuffer(Util.nonNativeByteOrder);
assertEquals(buf.getShort(0), 256);
diff --git a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
index 54c9515..988d2ee 100644
--- a/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/WritableMemoryTest.java
@@ -27,10 +27,10 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.datasketches.memory.internal.Memory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.internal.WritableBuffer;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
@@ -39,7 +39,7 @@ public class WritableMemoryTest {
@Test
public void wrapBigEndian() {
ByteBuffer bb = ByteBuffer.allocate(64); //big endian
- WritableMemory wmem = WritableMemory.writableWrap(bb);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bb);
assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
}
@@ -47,22 +47,22 @@ public class WritableMemoryTest {
public void wrapBigEndianAsLittle() {
ByteBuffer bb = ByteBuffer.allocate(64);
bb.putChar(0, (char)1); //as BE
- WritableMemory wmem = WritableMemory.writableWrap(bb, ByteOrder.LITTLE_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(bb, ByteOrder.LITTLE_ENDIAN);
assertEquals(wmem.getChar(0), 256);
}
@Test
public void allocateWithByteOrder() {
- WritableMemory wmem = WritableMemory.allocate(64, ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(64, ByteOrder.BIG_ENDIAN);
assertEquals(wmem.getTypeByteOrder(), ByteOrder.BIG_ENDIAN);
- wmem = WritableMemory.allocate(64, ByteOrder.LITTLE_ENDIAN);
+ wmem = WritableMemoryImpl.allocate(64, ByteOrder.LITTLE_ENDIAN);
assertEquals(wmem.getTypeByteOrder(), ByteOrder.LITTLE_ENDIAN);
}
@Test
public void checkGetArray() {
byte[] byteArr = new byte[64];
- WritableMemory wmem = WritableMemory.writableWrap(byteArr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteArr);
assertTrue(wmem.getArray() == byteArr);
WritableBuffer wbuf = wmem.asWritableBuffer();
assertTrue(wbuf.getArray() == byteArr);
@@ -71,26 +71,26 @@ public class WritableMemoryTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkSelfArrayCopy() {
byte[] srcAndDst = new byte[128];
- WritableMemory wmem = WritableMemory.writableWrap(srcAndDst);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(srcAndDst);
wmem.getByteArray(0, srcAndDst, 64, 64); //non-overlapping
}
@Test
public void checkEquals() {
int len = 7;
- WritableMemory wmem1 = WritableMemory.allocate(len);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.allocate(len);
//@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);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.allocate(len + 1);
assertFalse(wmem1.equals(wmem2));
- WritableMemory reg1 = wmem1.writableRegion(0, wmem1.getCapacity());
+ WritableMemoryImpl reg1 = wmem1.writableRegion(0, wmem1.getCapacity());
assertTrue(wmem1.equals(reg1));
- wmem2 = WritableMemory.allocate(len);
+ wmem2 = WritableMemoryImpl.allocate(len);
for (int i = 0; i < len; i++) {
wmem1.putByte(i, (byte) i);
wmem2.putByte(i, (byte) i);
@@ -102,8 +102,8 @@ public class WritableMemoryTest {
assertTrue(wmem1.equalTo(0, reg1, 0, len));
len = 24;
- wmem1 = WritableMemory.allocate(len);
- wmem2 = WritableMemory.allocate(len);
+ wmem1 = WritableMemoryImpl.allocate(len);
+ wmem2 = WritableMemoryImpl.allocate(len);
for (int i = 0; i < len; i++) {
wmem1.putByte(i, (byte) i);
wmem2.putByte(i, (byte) i);
@@ -120,14 +120,14 @@ public class WritableMemoryTest {
@Test
public void checkEquals2() {
int len = 23;
- WritableMemory wmem1 = WritableMemory.allocate(len);
+ WritableMemoryImpl wmem1 = WritableMemoryImpl.allocate(len);
assertFalse(wmem1.equals(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);
+ WritableMemoryImpl wmem2 = WritableMemoryImpl.allocate(len + 1);
assertFalse(wmem1.equals(wmem2));
for (int i = 0; i < len; i++) {
@@ -146,8 +146,8 @@ public class WritableMemoryTest {
byte[] bytes1 = new byte[(thresh * 2) + 7];
ThreadLocalRandom.current().nextBytes(bytes1);
byte[] bytes2 = bytes1.clone();
- Memory mem1 = Memory.wrap(bytes1);
- Memory mem2 = Memory.wrap(bytes2);
+ MemoryImpl mem1 = MemoryImpl.wrap(bytes1);
+ MemoryImpl mem2 = MemoryImpl.wrap(bytes2);
assertTrue(mem1.equals(mem2));
bytes2[thresh + 10] = (byte) (bytes1[thresh + 10] + 1);
@@ -160,11 +160,11 @@ public class WritableMemoryTest {
@Test
public void checkWrapWithBO() {
- WritableMemory wmem = WritableMemory.writableWrap(new byte[0], ByteOrder.BIG_ENDIAN);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(new byte[0], ByteOrder.BIG_ENDIAN);
boolean nativeBO = wmem.getTypeByteOrder() == Util.nativeByteOrder;
assertTrue(nativeBO); //remains true for ZeroSizeMemory
println("" + nativeBO);
- wmem = WritableMemory.writableWrap(new byte[8], ByteOrder.BIG_ENDIAN);
+ wmem = WritableMemoryImpl.writableWrap(new byte[8], ByteOrder.BIG_ENDIAN);
nativeBO = wmem.getTypeByteOrder() == Util.nativeByteOrder;
assertFalse(nativeBO);
println("" + nativeBO);
@@ -173,11 +173,11 @@ public class WritableMemoryTest {
@Test
@SuppressWarnings("unused")
public void checkOwnerClientCase() {
- WritableMemory owner = WritableMemory.allocate(64);
- Memory client1 = owner; //Client1 cannot write (no API)
+ WritableMemoryImpl owner = WritableMemoryImpl.allocate(64);
+ MemoryImpl client1 = owner; //Client1 cannot write (no API)
owner.putInt(0, 1); //But owner can write
- ((WritableMemory)client1).putInt(0, 2); //Client1 can write, but with explicit effort.
- Memory client2 = owner.region(0, owner.getCapacity()); //client2 cannot write (no API)
+ ((WritableMemoryImpl)client1).putInt(0, 2); //Client1 can write, but with explicit effort.
+ MemoryImpl client2 = owner.region(0, owner.getCapacity()); //client2 cannot write (no API)
owner.putInt(0, 3); //But Owner should be able to write
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java b/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
index 6d5cd76..6d1f6c1 100644
--- a/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/XxHash64LoopingTest.java
@@ -21,7 +21,7 @@ package org.apache.datasketches.memory.test;
import static org.testng.Assert.assertEquals;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
/**
@@ -42,7 +42,7 @@ public class XxHash64LoopingTest {
for (int i = 0; i < 1025; i++) {
byte[] byteArr = new byte[i];
for (int j = 0; j < byteArr.length; j++) { byteArr[j] = (byte) j; }
- WritableMemory wmem = WritableMemory.writableWrap(byteArr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(byteArr);
long hash = wmem.xxHash64(0, byteArr.length, seed);
assertEquals(hash, HASHES_OF_LOOPING_BYTES_WITH_SEED_42[i]);
}
diff --git a/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java b/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
index bf7924e..50f44c4 100644
--- a/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
+++ b/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java
@@ -26,8 +26,8 @@ import static org.testng.Assert.assertTrue;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.annotations.Test;
import net.openhft.hashing.LongHashFunction;
@@ -46,7 +46,7 @@ public class XxHash64Test {
long hash;
- WritableMemory wmem = WritableMemory.allocate(cap);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(cap);
for (int i = 0; i < cap; i++) { wmem.putByte(i, (byte)(-128 + i)); }
for (int offset = 0; offset < 16; offset++) {
@@ -65,7 +65,7 @@ public class XxHash64Test {
for (int j = 1; j < bytes; j++) {
byte[] in = new byte[bytes];
- WritableMemory wmem = WritableMemory.writableWrap(in);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(in);
for (int i = 0; i < j; i++) { wmem.putByte(i, (byte) (-128 + i)); }
long hash =wmem.xxHash64(offset, bytes, seed);
@@ -81,7 +81,7 @@ public class XxHash64Test {
*/
@Test
public void collisionTest() {
- WritableMemory wmem = WritableMemory.allocate(128);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(128);
wmem.putLong(0, 1);
wmem.putLong(16, 42);
wmem.putLong(32, 2);
@@ -115,7 +115,7 @@ public class XxHash64Test {
byte[] bytes = new byte[len];
for (int i = 0; i < 10; i++) {
long zahXxHash = LongHashFunction.xx().hashBytes(bytes);
- long memoryXxHash = Memory.wrap(bytes).xxHash64(0, len, 0);
+ long memoryXxHash = MemoryImpl.wrap(bytes).xxHash64(0, len, 0);
assertEquals(memoryXxHash, zahXxHash);
random.nextBytes(bytes);
}
@@ -126,7 +126,7 @@ public class XxHash64Test {
@Test
public void testArrHashes() {
- WritableMemory wmem = WritableMemory.writableWrap(barr);
+ WritableMemoryImpl wmem = WritableMemoryImpl.writableWrap(barr);
long hash0 = wmem.xxHash64(8, 8, 0);
long hash1 = hashBytes(barr, 8, 8, 0);
assertEquals(hash1, hash0);
diff --git a/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java b/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
index b8b3e3d..fea92ae 100644
--- a/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
+++ b/src/test/java/org/apache/datasketches/memory/test/ZeroCapacityTest.java
@@ -23,8 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.nio.ByteBuffer;
-import org.apache.datasketches.memory.internal.Memory;
-import org.apache.datasketches.memory.internal.WritableMemory;
+import org.apache.datasketches.memory.internal.MemoryImpl;
+import org.apache.datasketches.memory.internal.WritableMemoryImpl;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -37,15 +37,15 @@ public class ZeroCapacityTest {
@SuppressWarnings({ "unused", "resource" })
@Test
public void checkZeroCapacity() {
- WritableMemory wmem = WritableMemory.allocate(0);
+ WritableMemoryImpl wmem = WritableMemoryImpl.allocate(0);
assertEquals(wmem.getCapacity(), 0);
- Memory mem1 = Memory.wrap(new byte[0]);
- Memory mem2 = Memory.wrap(ByteBuffer.allocate(0));
- Memory mem3 = Memory.wrap(ByteBuffer.allocateDirect(0));
- Memory reg = mem3.region(0, 0);
+ MemoryImpl mem1 = MemoryImpl.wrap(new byte[0]);
+ MemoryImpl mem2 = MemoryImpl.wrap(ByteBuffer.allocate(0));
+ MemoryImpl mem3 = MemoryImpl.wrap(ByteBuffer.allocateDirect(0));
+ MemoryImpl reg = mem3.region(0, 0);
try {
- WritableMemory.allocateDirect(0);
+ WritableMemoryImpl.allocateDirect(0);
Assert.fail();
} catch (IllegalArgumentException ignore) {
// expected
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org