You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2022/12/16 23:41:12 UTC
[datasketches-memory] branch IntegrateJava17_v2 updated: Removed unnecessary methods from Java 8
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch IntegrateJava17_v2
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
The following commit(s) were added to refs/heads/IntegrateJava17_v2 by this push:
new 308b855 Removed unnecessary methods from Java 8
308b855 is described below
commit 308b8552346e0ae917d5fa066c5ce373a36108cb
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Fri Dec 16 15:40:58 2022 -0800
Removed unnecessary methods from Java 8
And changed some public methods to package private.
Simplified and separated some complex methods to their base components.
---
.../memory/internal/BaseStateImpl.java | 44 +--
.../memory/internal/BaseStateTest.java | 2 +-
.../org/apache/datasketches/memory/BaseState.java | 112 +-----
.../apache/datasketches/memory/MurmurHash3v2.java | 360 ------------------
.../internal/BBNonNativeWritableBufferImpl.java | 8 +-
.../internal/BBNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/BBWritableBufferImpl.java | 8 +-
.../memory/internal/BBWritableMemoryImpl.java | 4 +-
.../memory/internal/BaseBufferImpl.java | 2 +-
.../memory/internal/BaseStateImpl.java | 85 ++---
.../memory/internal/BaseWritableBufferImpl.java | 47 ++-
.../memory/internal/BaseWritableMemoryImpl.java | 81 +++--
.../DirectNonNativeWritableBufferImpl.java | 8 +-
.../DirectNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/DirectWritableBufferImpl.java | 8 +-
.../memory/internal/DirectWritableMemoryImpl.java | 4 +-
.../internal/HeapNonNativeWritableBufferImpl.java | 8 +-
.../internal/HeapNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/HeapWritableBufferImpl.java | 8 +-
.../memory/internal/HeapWritableMemoryImpl.java | 4 +-
.../internal/MapNonNativeWritableBufferImpl.java | 8 +-
.../internal/MapNonNativeWritableMemoryImpl.java | 4 +-
.../memory/internal/MapWritableBufferImpl.java | 8 +-
.../memory/internal/MapWritableMemoryImpl.java | 4 +-
.../memory/internal/NativeWritableBufferImpl.java | 14 +-
.../memory/internal/NativeWritableMemoryImpl.java | 68 +++-
.../internal/NonNativeWritableBufferImpl.java | 14 +-
.../internal/NonNativeWritableMemoryImpl.java | 70 +++-
.../memory/internal/BaseStateTest.java | 10 -
.../datasketches/memory/internal/Buffer2Test.java | 4 -
.../datasketches/memory/internal/BufferTest.java | 2 +-
.../datasketches/memory/internal/LeafImplTest.java | 8 +-
.../datasketches/memory/internal/MemoryTest.java | 7 -
.../memory/internal/MurmurHash3v2Test.java | 401 ---------------------
.../internal/NativeWritableBufferImplTest.java | 14 +-
.../internal/NativeWritableMemoryImplTest.java | 12 +-
36 files changed, 329 insertions(+), 1124 deletions(-)
diff --git a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 55e1c8a..b95f90e 100644
--- a/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java17/src/main/java17/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -135,7 +135,7 @@ abstract class BaseStateImpl implements BaseState {
}
}
- static String pad(final String s, final int fieldLen) {
+ private static String pad(final String s, final int fieldLen) {
return characterPad(s, fieldLen, ' ' , true);
}
@@ -159,7 +159,7 @@ abstract class BaseStateImpl implements BaseState {
return new int[] {p0, p1};
}
- static final WritableBuffer selectBuffer(
+ static final WritableBuffer selectBuffer( //Java 17 only
final MemorySegment segment,
final int type,
final MemoryRequestServer memReqSvr,
@@ -176,7 +176,7 @@ abstract class BaseStateImpl implements BaseState {
return wbuf;
}
- static final WritableMemory selectMemory(
+ static final WritableMemory selectMemory( //Java 17 only
final MemorySegment segment,
final int type,
final MemoryRequestServer memReqSvr,
@@ -225,7 +225,7 @@ abstract class BaseStateImpl implements BaseState {
sb.append("MemReqSvr, hashCode : ").append(memReqStr).append(LS);
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
sb.append("Type Byte Order : ").append(state.getByteOrder().toString()).append(LS);
- sb.append("Native Byte Order : ").append(ByteOrder.nativeOrder().toString()).append(LS);
+ sb.append("Native Byte Order : ").append(NATIVE_BYTE_ORDER.toString()).append(LS);
sb.append("JDK Runtime Version : ").append(JDK).append(LS);
//Data detail
if (withData) {
@@ -302,7 +302,7 @@ abstract class BaseStateImpl implements BaseState {
//@SuppressWarnings("resource")
@Override
- public void close() {
+ public void close() { //moved here
if (seg != null && seg.scope().isAlive() && !seg.scope().isImplicit()) {
if (seg.isNative() || seg.isMapped()) {
seg.scope().close();
@@ -318,16 +318,16 @@ abstract class BaseStateImpl implements BaseState {
}
@Override
- public void force() { seg.force(); }
+ public void force() { seg.force(); } //moved here
@Override
- public final long getCapacity() {
- return seg.byteSize();
+ public final ByteOrder getByteOrder() {
+ return (typeId & NONNATIVE) > 0 ? NON_NATIVE_BYTE_ORDER : NATIVE_BYTE_ORDER;
}
@Override
- public final ByteOrder getByteOrder() {
- return (typeId & NONNATIVE) > 0 ? NON_NATIVE_BYTE_ORDER : NATIVE_BYTE_ORDER;
+ public final long getCapacity() {
+ return seg.byteSize();
}
@Override
@@ -347,7 +347,9 @@ abstract class BaseStateImpl implements BaseState {
//@SuppressWarnings("resource")
@Override
- public boolean isAlive() { return seg.scope().isAlive(); }
+ public boolean isAlive() { //Java 17 only
+ return seg.scope().isAlive();
+ }
@Override
public final boolean isBuffer() {
@@ -357,7 +359,7 @@ abstract class BaseStateImpl implements BaseState {
@Override
public final boolean isByteOrderCompatible(final ByteOrder byteOrder) {
final ByteOrder typeBO = getByteOrder();
- return typeBO == ByteOrder.nativeOrder() && typeBO == byteOrder;
+ return typeBO == NATIVE_BYTE_ORDER && typeBO == byteOrder;
}
@Override
@@ -402,10 +404,10 @@ abstract class BaseStateImpl implements BaseState {
}
@Override
- public void load() { seg.load(); }
+ public void load() { seg.load(); } //moved here
@Override
- public long mismatch(final BaseState that) {
+ public long mismatch(final BaseState that) { //Java 17 only
Objects.requireNonNull(that);
if (!that.isAlive()) { throw new IllegalArgumentException("Given argument is not alive."); }
BaseStateImpl thatBSI = (BaseStateImpl) that;
@@ -413,7 +415,7 @@ abstract class BaseStateImpl implements BaseState {
}
@Override
- public final long nativeOverlap(final BaseState that) {
+ public final long nativeOverlap(final BaseState that) { //Java 17 only
if (that == null) { return 0; }
if (!that.isAlive()) { return 0; }
BaseStateImpl thatBSI = (BaseStateImpl) that;
@@ -421,7 +423,7 @@ abstract class BaseStateImpl implements BaseState {
return nativeOverlap(seg, thatBSI.seg);
}
- static final long nativeOverlap(final MemorySegment segA, final MemorySegment segB) { //used in test
+ static final long nativeOverlap(final MemorySegment segA, final MemorySegment segB) { // //Java 17 only; used in test
if (!segA.isNative() || !segB.isNative()) { return 0; } //both segments must be native
//Assume that memory addresses increase from left to right.
//Identify the left and right edges of two regions, A and B in memory.
@@ -461,21 +463,21 @@ abstract class BaseStateImpl implements BaseState {
}
@Override
- public ResourceScope scope() { return seg.scope(); }
+ public ResourceScope scope() { return seg.scope(); } //Java 17 only
@Override
- public ByteBuffer toByteBuffer(final ByteOrder order) {
+ public ByteBuffer toByteBuffer(final ByteOrder order) { //Java 17 only
Objects.requireNonNull(order, "The input ByteOrder must not be null");
return ByteBuffer.wrap(seg.toByteArray());
}
- @Override
+ @Override //Java 17 only
public final String toHexString(final String comment, final long offsetBytes, final int lengthBytes,
final boolean withData) {
return toHex(this, comment, offsetBytes, lengthBytes, withData);
}
- @Override
+ @Override //Java 17 only
public MemorySegment toMemorySegment() {
final MemorySegment arrSeg = MemorySegment.ofArray(new byte[(int)seg.byteSize()]);
arrSeg.copyFrom(seg);
@@ -483,7 +485,7 @@ abstract class BaseStateImpl implements BaseState {
}
@Override
- public void unload() { seg.unload(); }
+ public void unload() { seg.unload(); } //moved here
@Override
public final long xxHash64(final long in, final long seed) {
diff --git a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/BaseStateTest.java b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/BaseStateTest.java
index 793cc8b..181afc2 100644
--- a/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/BaseStateTest.java
+++ b/datasketches-memory-java17/src/test/java17/org/apache/datasketches/memory/internal/BaseStateTest.java
@@ -134,7 +134,7 @@ public class BaseStateTest {
* @param s value to print
*/
static void println(String s) {
- System.out.println(s); //disable here
+ //System.out.println(s); //disable here
}
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
index bf0127f..c17f14c 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/BaseState.java
@@ -19,7 +19,6 @@
package org.apache.datasketches.memory;
-import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
@@ -77,6 +76,13 @@ public interface BaseState {
*/
boolean hasByteBuffer();
+// /**
+// * Is this resource alive?
+// * @return true, if this resource is alive. That is, it has not been closed.
+// * @see close()
+// */
+// boolean isAlive();
+
/**
* Returns true if the Native ByteOrder is the same as the ByteOrder of the
* current Buffer or Memory and the same ByteOrder as the given byteOrder.
@@ -134,106 +140,6 @@ public interface BaseState {
//DEPRECATED. DOES NOT EXIST FOR JAVA 17+ VERSIONS
- /**
- * Checks that the specified range of bytes is within bounds of this object, throws
- * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes < 0, or length < 0,
- * or offsetBytes + length > {@link #getCapacity()}.
- * @param offsetBytes the given offset in bytes of this object
- * @param lengthBytes the given length in bytes of this object
- * @deprecated no longer supported for Java 17 versions.
- */
- @Deprecated
- void checkValidAndBounds(long offsetBytes, long lengthBytes);
-
- /**
- * Gets the backing ByteBuffer if it exists, otherwise returns null.
- * @return the backing ByteBuffer if it exists, otherwise returns null.
- * @deprecated no longer supported for Java 17 versions.
- * In Java 17 use toByteBuffer(ByteOrder) or asByteBufferView(ByteOrder) instead.
- */
- @Deprecated
- ByteBuffer getByteBuffer();
-
- /**
- * Gets the cumulative offset in bytes of this object from the backing resource.
- * This offset may also include other offset components such as the native off-heap
- * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets.
- *
- * @return the cumulative offset in bytes of this object from the backing resource.
- * @deprecated no longer supported for Java 17 versions. Use nativeOverlap(BaseState) instead.
- */
- @Deprecated
- long getCumulativeOffset();
-
- /**
- * Gets the cumulative offset in bytes of this object from the backing resource including the given
- * offsetBytes. This offset may also include other offset components such as the native off-heap
- * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets.
- *
- * @param offsetBytes offset to be added to the cumulative offset.
- * @return the cumulative offset in bytes of this object from the backing resource including the
- * given offsetBytes.
- * @deprecated no longer supported for Java 17 versions. Use nativeOverlap(BaseState) instead.
- */
- @Deprecated
- long getCumulativeOffset(long offsetBytes);
-
- /**
- * Returns the offset of address zero of this object relative to the address zero of the
- * backing resource but not including the size of any Java object header.
- * @return the offset of address zero of this object relative to the address zero of the
- * backing resource but not including the size of any Java object header.
- * @deprecated no longer supported for Java17 versions use nativeOverlap(BaseState) instead.
- */
- @Deprecated
- long getRegionOffset();
-
- /**
- * Returns the offset of address zero of this object relative to the address zero of the
- * backing resource plus the given offsetBytes but not including the size of any Java object
- * header.
- * @param offsetBytes the given offsetBytes
- * @return the offset of address zero of this object relative to the address zero of the
- * backing resource plus the given offsetBytes but not including the size of any Java object
- * header.
- * @deprecated no longer supported for Java 17 versions. Use nativeOverlap(BaseState) instead.
- */
- @Deprecated
- long getRegionOffset(long offsetBytes);
-
- /**
- * Gets the current Type ByteOrder.
- * This may be different from the ByteOrder of the backing resource and of the Native Byte Order.
- * @return the current Type ByteOrder.
- * @deprecated use getByteOrder() instead.
- */
- @Deprecated
- default ByteOrder getTypeByteOrder() { return getByteOrder(); }
-
- /**
- * Returns true if this object is backed by an on-heap primitive array
- * @return true if this object is backed by an on-heap primitive array
- * @deprecated no longer supported for Java 17 versions.
- */
- @Deprecated
- boolean hasArray();
-
- /**
- * Returns the hashCode of this object.
- *
- * <p>The hash code of this object depends upon all of its contents.
- * Because of this, it is inadvisable to use these objects as keys in hash maps
- * or similar data structures unless it is known that their contents will not change.</p>
- *
- * <p>If it is desirable to use these objects in a hash map depending only on object identity,
- * than the {@link java.util.IdentityHashMap} can be used.</p>
- *
- * @return the hashCode of this object.
- * @apiNote This custom hashCode() will no longer be supported for Java 17 versions.
- */
- @Override
- int hashCode();
-
/**
* Returns true if the backing resource of <i>this</i> is identical with the backing resource
* of <i>that</i>. The capacities must be the same. If <i>this</i> is a region,
@@ -250,9 +156,9 @@ public interface BaseState {
* Returns true if this object is valid and has not been closed.
* This is relevant only for direct (off-heap) memory and Mapped Files.
* @return true if this object is valid and has not been closed.
- * @deprecated no longer required or supported for Java 17 versions.
+ * deprecated no longer supported for Java 17 versions. Use <i>isAlive()</i> instead
*/
- @Deprecated
+ //@Deprecated
boolean isValid();
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
deleted file mode 100644
index 245f3a9..0000000
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.datasketches.memory;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
-
-/**
- * <p>The MurmurHash3 is a fast, non-cryptographic, 128-bit hash function that has
- * excellent avalanche and 2-way bit independence properties.</p>
- *
- * <p>Austin Appleby's C++
- * <a href="https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp">
- * MurmurHash3_x64_128(...), final revision 150</a>,
- * which is in the Public Domain, was the inspiration for this implementation in Java.</p>
- *
- * <p>This implementation of the MurmurHash3 allows hashing of a block of on-heap Memory defined by an offset
- * and length. The calling API also allows the user to supply the small output array of two longs,
- * so that the entire hash function is static and free of object allocations.</p>
- *
- * <p>This implementation produces exactly the same hash result as the
- * MurmurHash3 function in datasketches-java given compatible inputs.</p>
- *
- * @author Lee Rhodes
- */
-@SuppressWarnings("deprecation")
-public final class MurmurHash3v2 {
- private static final long C1 = 0x87c37b91114253d5L;
- private static final long C2 = 0x4cf5ad432745937fL;
-
- //Provided for backward compatibility
-
- /**
- * Returns a 128-bit hash of the input.
- * Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now throws IllegalArgumentException.
- * @param in long array
- * @param seed A long valued seed.
- * @return the hash
- */
- public static long[] hash(final long[] in, final long seed) {
- if ((in == null) || (in.length == 0)) {
- throw new IllegalArgumentException("Input in is empty or null.");
- }
- return hash(Memory.wrap(in), 0L, in.length << 3, seed, new long[2]);
- }
-
- /**
- * Returns a 128-bit hash of the input.
- * Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now throws IllegalArgumentException.
- * @param in int array
- * @param seed A long valued seed.
- * @return the hash
- */
- public static long[] hash(final int[] in, final long seed) {
- if ((in == null) || (in.length == 0)) {
- throw new IllegalArgumentException("Input in is empty or null.");
- }
- return hash(Memory.wrap(in), 0L, in.length << 2, seed, new long[2]);
- }
-
- /**
- * Returns a 128-bit hash of the input.
- * Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now throws IllegalArgumentException.
- * @param in char array
- * @param seed A long valued seed.
- * @return the hash
- */
- public static long[] hash(final char[] in, final long seed) {
- if ((in == null) || (in.length == 0)) {
- throw new IllegalArgumentException("Input in is empty or null.");
- }
- return hash(Memory.wrap(in), 0L, in.length << 1, seed, new long[2]);
- }
-
- /**
- * Returns a 128-bit hash of the input.
- * Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now throws IllegalArgumentException.
- * @param in byte array
- * @param seed A long valued seed.
- * @return the hash
- */
- public static long[] hash(final byte[] in, final long seed) {
- if ((in == null) || (in.length == 0)) {
- throw new IllegalArgumentException("Input in is empty or null.");
- }
- return hash(Memory.wrap(in), 0L, in.length, seed, new long[2]);
- }
-
- //Single primitive inputs
-
- /**
- * Returns a 128-bit hash of the input.
- * Note the entropy of the resulting hash cannot be more than 64 bits.
- * @param in a long
- * @param seed A long valued seed.
- * @param hashOut A long array of size 2
- * @return the hash
- */
- public static long[] hash(final long in, final long seed, final long[] hashOut) {
- final long h1 = seed ^ mixK1(in);
- final long h2 = seed;
- return finalMix128(h1, h2, 8, hashOut);
- }
-
- /**
- * Returns a 128-bit hash of the input.
- * Note the entropy of the resulting hash cannot be more than 64 bits.
- * @param in a double
- * @param seed A long valued seed.
- * @param hashOut A long array of size 2
- * @return the hash
- */
- public static long[] hash(final double in, final long seed, final long[] hashOut) {
- final double d = (in == 0.0) ? 0.0 : in; // canonicalize -0.0, 0.0
- final long k1 = Double.doubleToLongBits(d); // canonicalize all NaN forms
- final long h1 = seed ^ mixK1(k1);
- final long h2 = seed;
- return finalMix128(h1, h2, 8, hashOut);
- }
-
- /**
- * Returns a 128-bit hash of the input.
- * An empty or null input throws IllegalArgumentException.
- * @param in a String
- * @param seed A long valued seed.
- * @param hashOut A long array of size 2
- * @return the hash
- */
- public static long[] hash(final String in, final long seed, final long[] hashOut) {
- if ((in == null) || (in.length() == 0)) {
- throw new IllegalArgumentException("Input in is empty or null.");
- }
- final byte[] byteArr = in.getBytes(UTF_8);
- return hash(Memory.wrap(byteArr), 0L, byteArr.length, seed, hashOut);
- }
-
- //The main API call
-
- /**
- * Returns a 128-bit hash of the input as a long array of size 2.
- *
- * @param mem The input on-heap Memory. Must be non-null and non-empty,
- * otherwise throws IllegalArgumentException.
- * @param offsetBytes the starting point within Memory.
- * @param lengthBytes the total number of bytes to be hashed.
- * @param seed A long valued seed.
- * @param hashOut the size 2 long array for the resulting 128-bit hash
- * @return the hash.
- */
- @SuppressWarnings("restriction")
- public static long[] hash(final Memory mem, final long offsetBytes, final long lengthBytes,
- final long seed, final long[] hashOut) {
- if ((mem == null) || (mem.getCapacity() == 0L)) {
- throw new IllegalArgumentException("Input mem is empty or null.");
- }
- final Object uObj = ((WritableMemory) mem).getArray();
- if (uObj == null) {
- throw new IllegalArgumentException("The backing resource of input mem is not on-heap.");
- }
- long cumOff = mem.getCumulativeOffset() + offsetBytes;
-
- long h1 = seed;
- long h2 = seed;
- long rem = lengthBytes;
-
- // Process the 128-bit blocks (the body) into the hash
- while (rem >= 16L) {
- final long k1 = unsafe.getLong(uObj, cumOff); //0, 16, 32, ...
- final long k2 = unsafe.getLong(uObj, cumOff + 8); //8, 24, 40, ...
- cumOff += 16L;
- rem -= 16L;
-
- h1 ^= mixK1(k1);
- h1 = Long.rotateLeft(h1, 27);
- h1 += h2;
- h1 = (h1 * 5) + 0x52dce729L;
-
- h2 ^= mixK2(k2);
- h2 = Long.rotateLeft(h2, 31);
- h2 += h1;
- h2 = (h2 * 5) + 0x38495ab5L;
- }
-
- // Get the tail (if any): 1 to 15 bytes
- if (rem > 0L) {
- long k1 = 0;
- long k2 = 0;
- switch ((int) rem) {
- case 15: {
- k2 ^= (unsafe.getByte(uObj, cumOff + 14) & 0xFFL) << 48;
- }
- //$FALL-THROUGH$
- case 14: {
- k2 ^= (unsafe.getShort(uObj, cumOff + 12) & 0xFFFFL) << 32;
- k2 ^= (unsafe.getInt(uObj, cumOff + 8) & 0xFFFFFFFFL);
- k1 = unsafe.getLong(uObj, cumOff);
- break;
- }
-
- case 13: {
- k2 ^= (unsafe.getByte(uObj, cumOff + 12) & 0xFFL) << 32;
- }
- //$FALL-THROUGH$
- case 12: {
- k2 ^= (unsafe.getInt(uObj, cumOff + 8) & 0xFFFFFFFFL);
- k1 = unsafe.getLong(uObj, cumOff);
- break;
- }
-
- case 11: {
- k2 ^= (unsafe.getByte(uObj, cumOff + 10) & 0xFFL) << 16;
- }
- //$FALL-THROUGH$
- case 10: {
- k2 ^= (unsafe.getShort(uObj, cumOff + 8) & 0xFFFFL);
- k1 = unsafe.getLong(uObj, cumOff);
- break;
- }
-
- case 9: {
- k2 ^= (unsafe.getByte(uObj, cumOff + 8) & 0xFFL);
- }
- //$FALL-THROUGH$
- case 8: {
- k1 = unsafe.getLong(uObj, cumOff);
- break;
- }
-
- case 7: {
- k1 ^= (unsafe.getByte(uObj, cumOff + 6) & 0xFFL) << 48;
- }
- //$FALL-THROUGH$
- case 6: {
- k1 ^= (unsafe.getShort(uObj, cumOff + 4) & 0xFFFFL) << 32;
- k1 ^= (unsafe.getInt(uObj, cumOff) & 0xFFFFFFFFL);
- break;
- }
-
- case 5: {
- k1 ^= (unsafe.getByte(uObj, cumOff + 4) & 0xFFL) << 32;
- }
- //$FALL-THROUGH$
- case 4: {
- k1 ^= (unsafe.getInt(uObj, cumOff) & 0xFFFFFFFFL);
- break;
- }
-
- case 3: {
- k1 ^= (unsafe.getByte(uObj, cumOff + 2) & 0xFFL) << 16;
- }
- //$FALL-THROUGH$
- case 2: {
- k1 ^= (unsafe.getShort(uObj, cumOff) & 0xFFFFL);
- break;
- }
-
- case 1: {
- k1 ^= (unsafe.getByte(uObj, cumOff) & 0xFFL);
- break;
- }
- //default: break; //can't happen
- }
-
- h1 ^= mixK1(k1);
- h2 ^= mixK2(k2);
- }
- return finalMix128(h1, h2, lengthBytes, hashOut);
- }
-
- //--Helper methods----------------------------------------------------
-
- /**
- * Self mix of k1
- *
- * @param k1 input argument
- * @return mix
- */
- private static long mixK1(long k1) {
- k1 *= C1;
- k1 = Long.rotateLeft(k1, 31);
- k1 *= C2;
- return k1;
- }
-
- /**
- * Self mix of k2
- *
- * @param k2 input argument
- * @return mix
- */
- private static long mixK2(long k2) {
- k2 *= C2;
- k2 = Long.rotateLeft(k2, 33);
- k2 *= C1;
- return k2;
- }
-
- /**
- * Final self mix of h*.
- *
- * @param h input to final mix
- * @return mix
- */
- private static long finalMix64(long h) {
- h ^= h >>> 33;
- h *= 0xff51afd7ed558ccdL;
- h ^= h >>> 33;
- h *= 0xc4ceb9fe1a85ec53L;
- h ^= h >>> 33;
- return h;
- }
-
- /**
- * Finalization: Add the length into the hash and mix
- * @param h1 intermediate hash
- * @param h2 intermediate hash
- * @param lengthBytes the length in bytes
- * @param hashOut the output array of 2 longs
- * @return hashOut
- */
- private static long[] finalMix128(long h1, long h2, final long lengthBytes, final long[] hashOut) {
- h1 ^= lengthBytes;
- h2 ^= lengthBytes;
-
- h1 += h2;
- h2 += h1;
-
- h1 = finalMix64(h1);
- h2 = finalMix64(h2);
-
- h1 += h2;
- h2 += h1;
-
- hashOut[0] = h1;
- hashOut[1] = h2;
- return hashOut;
- }
-
-}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
index 431063c..17a9e36 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableBufferImpl.java
@@ -71,9 +71,9 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new BBWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
@@ -81,9 +81,9 @@ final class BBNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new BBWritableMemoryImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableMemoryImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
index f119924..b1c8482 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBNonNativeWritableMemoryImpl.java
@@ -71,9 +71,9 @@ final class BBNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new BBWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
index dd25f1d..fac0215 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableBufferImpl.java
@@ -71,9 +71,9 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new BBWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
@@ -81,9 +81,9 @@ final class BBWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new BBWritableMemoryImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableMemoryImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
index 7b4d87a..27143dd 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BBWritableMemoryImpl.java
@@ -71,9 +71,9 @@ final class BBWritableMemoryImpl extends NativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new BBWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr)
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr)
: new BBNonNativeWritableBufferImpl(
- unsafeObj, nativeBaseOffset, getRegionOffset(), getCapacity(), type, byteBuf, memReqSvr);
+ unsafeObj, nativeBaseOffset, getRegionOffset(0), getCapacity(), type, byteBuf, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
index 19664c8..68c699e 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseBufferImpl.java
@@ -127,7 +127,7 @@ public abstract class BaseBufferImpl extends BaseStateImpl implements BaseBuffer
final void checkValidForWrite() {
checkValid();
if (isReadOnly()) {
- throw new ReadOnlyException("BufferImpl is read-only.");
+ throw new ReadOnlyException("Buffer is read-only.");
}
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
index 0826c2e..9c2bb0e 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java
@@ -93,14 +93,14 @@ public abstract class BaseStateImpl implements BaseState {
JDK_MAJOR = (p[0] == 1) ? p[1] : p[0];
}
- private final long capacityBytes_; //NOT USED in JDK 17
+ final long capacityBytes_; //NOT USED in JDK 17
/**
* 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 MemoryImpl, and the array object
* header offset when creating MemoryImpl from primitive arrays.
*/
- private final long cumBaseOffset_; //NOT USED in JDK 17
+ final long cumBaseOffset_; //NOT USED in JDK 17
/**
* Constructor
@@ -146,19 +146,7 @@ public abstract class BaseStateImpl implements BaseState {
}
}
- /**
- * Returns true if the given byteOrder is the same as the native byte order.
- * @param byteOrder the given byte order
- * @return true if the given byteOrder is the same as the native byte order.
- */
- static boolean isNativeByteOrder(final ByteOrder byteOrder) {
- if (byteOrder == null) {
- throw new IllegalArgumentException("ByteOrder parameter cannot be null.");
- }
- return NATIVE_BYTE_ORDER == byteOrder;
- }
-
- static String pad(final String s, final int fieldLen) {
+ private static String pad(final String s, final int fieldLen) {
return characterPad(s, fieldLen, ' ' , true);
}
@@ -183,7 +171,7 @@ public abstract class BaseStateImpl implements BaseState {
}
//REACHABILITY FENCE
- static void reachabilityFence(final Object obj) { }
+ static void reachabilityFence(final Object obj) { } //Java 8 & 11 only
final static byte setReadOnlyType(final byte type, final boolean readOnly) {
return (byte)((type & ~1) | (readOnly ? READONLY : 0));
@@ -220,15 +208,15 @@ public abstract class BaseStateImpl implements BaseState {
final String memReqStr = memReqSvr != null
? memReqSvr.getClass().getSimpleName() + ", " + (memReqSvr.hashCode() & 0XFFFFFFFFL)
: "null";
- final long cumBaseOffset = state.getCumulativeOffset();
+ final long cumBaseOffset = state.getCumulativeOffset(0);
sb.append(preamble).append(LS);
sb.append("UnsafeObj, hashCode : ").append(uObjStr).append(LS);
sb.append("UnsafeObjHeader : ").append(uObjHeader).append(LS);
sb.append("ByteBuf, hashCode : ").append(bbStr).append(LS);
- sb.append("RegionOffset : ").append(state.getRegionOffset()).append(LS);
+ sb.append("RegionOffset : ").append(state.getRegionOffset(0)).append(LS);
sb.append("Capacity : ").append(capacity).append(LS);
sb.append("CumBaseOffset : ").append(cumBaseOffset).append(LS);
- sb.append("MemReq, hashCode : ").append(memReqStr).append(LS);
+ sb.append("MemReqSvr, hashCode : ").append(memReqStr).append(LS);
sb.append("Valid : ").append(state.isValid()).append(LS);
sb.append("Read Only : ").append(state.isReadOnly()).append(LS);
sb.append("Type Byte Order : ").append(state.getByteOrder().toString()).append(LS);
@@ -299,25 +287,15 @@ public abstract class BaseStateImpl implements BaseState {
//**NON STATIC METHODS*****************************************
- void checkValid() {
+ void checkValid() { //Java 8 & 11 only
if (!isValid()) {
throw new IllegalStateException("Memory not valid.");
}
}
- @Override
- public final void checkValidAndBounds(final long offsetBytes, final long lengthBytes) {
- checkValid();
- //read capacityBytes_ directly to eliminate extra checkValid() call
- checkBounds(offsetBytes, lengthBytes, capacityBytes_);
- }
-
- final void checkValidBoundsWritable(final long offsetBytes, final long lengthBytes) {
- checkValid();
- //read capacityBytes_ directly to eliminate extra checkValid() call
- checkBounds(offsetBytes, lengthBytes, capacityBytes_);
+ void checkWritable() { //Java 8 & 11 only
if (isReadOnly()) {
- throw new ReadOnlyException("Memory is read-only.");
+ throw new ReadOnlyException("Resource is read-only.");
}
}
@@ -334,8 +312,8 @@ public abstract class BaseStateImpl implements BaseState {
}
//Overridden by ByteBuffer Leafs
- @Override
public ByteBuffer getByteBuffer() {
+ checkValid();
return null;
}
@@ -345,14 +323,7 @@ public abstract class BaseStateImpl implements BaseState {
return capacityBytes_;
}
- @Override
- public final long getCumulativeOffset() {
- checkValid();
- return cumBaseOffset_;
- }
-
- @Override
- public final long getCumulativeOffset(final long offsetBytes) {
+ public final long getCumulativeOffset(final long offsetBytes) { //Java 8 & 11 only
checkValid();
return cumBaseOffset_ + offsetBytes;
}
@@ -362,46 +333,34 @@ public abstract class BaseStateImpl implements BaseState {
abstract MemoryRequestServer getMemoryRequestServer();
//Overridden by ByteBuffer, Direct and Map leafs
- long getNativeBaseOffset() {
+ long getNativeBaseOffset() { //Java 8 & 11 only
return 0;
}
- @Override
- public final long getRegionOffset() {
+ public final long getRegionOffset(final long offsetBytes) { //Java 8 & 11 only
final Object unsafeObj = getUnsafeObject();
- return unsafeObj == null
+ return offsetBytes + (unsafeObj == null
? cumBaseOffset_ - getNativeBaseOffset()
- : cumBaseOffset_ - UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass());
- }
-
- @Override
- public final long getRegionOffset(final long offsetBytes) {
- return getRegionOffset() + offsetBytes;
+ : cumBaseOffset_ - UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass()));
}
//Overridden by all leafs
- abstract int getTypeId();
+ abstract int getTypeId(); //Java 8 & 11 only
//Overridden by Heap and ByteBuffer Leafs. Made public as getArray() in WritableMemoryImpl and
// WritableBufferImpl
- Object getUnsafeObject() {
+ Object getUnsafeObject() { //Java 8 & 11 only
return null;
}
@Override
- public final boolean hasArray() {
- checkValid();
- return getUnsafeObject() != null;
- }
-
- @Override
- public final boolean hasByteBuffer() {
+ public final boolean hasByteBuffer() { //Java 8 & 11 only
checkValid();
return isByteBufferType();
}
@Override
- public final int hashCode() {
+ public final int hashCode() { //Java 8 & 11 only
return (int) xxHash64(0, capacityBytes_, 0); //xxHash64() calls checkValid()
}
@@ -463,7 +422,7 @@ public abstract class BaseStateImpl implements BaseState {
}
@Override
- public final boolean isSameResource(final Object that) {
+ public final boolean isSameResource(final Object that) { //Java 8 & 11 only
checkValid();
if (that == null) { return false; }
final BaseStateImpl that1 = (BaseStateImpl) that;
@@ -478,7 +437,7 @@ public abstract class BaseStateImpl implements BaseState {
//Overridden by Direct and Map leafs
@Override
- public boolean isValid() {
+ public boolean isValid() { //Java 8 & 11 only
return true;
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
index cd6ce2c..4c1971a 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableBufferImpl.java
@@ -105,7 +105,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
if (isReadOnly() && !localReadOnly) {
throw new ReadOnlyException("Writable region of a read-only Buffer is not allowed.");
}
- checkValidAndBounds(offsetBytes, capacityBytes);
+ checkValid();
+ checkBounds(offsetBytes, capacityBytes, capacityBytes_);
final boolean readOnly = isReadOnly() || localReadOnly;
final WritableBuffer wbuf = toWritableRegion(offsetBytes, capacityBytes, readOnly, byteOrder);
wbuf.setAndCheckStartPositionEnd(0, 0, capacityBytes);
@@ -182,7 +183,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final boolean getBoolean(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE, capacityBytes_);
return unsafe.getBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -210,7 +212,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final byte getByte(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
return unsafe.getByte(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -237,7 +240,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final char getNativeOrderedChar(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE, capacityBytes_);
return unsafe.getChar(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -248,7 +252,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final int getNativeOrderedInt(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_INT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_INT_INDEX_SCALE, capacityBytes_);
return unsafe.getInt(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -259,7 +264,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final long getNativeOrderedLong(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
return unsafe.getLong(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -270,7 +276,8 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final short getNativeOrderedShort(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE, capacityBytes_);
return unsafe.getShort(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -283,7 +290,7 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
/*
- * Develper notes: There is no copyTo for Buffers because of the ambiguity of what to do with
+ * Developer note: There is no copyTo for Buffers because of the ambiguity of what to do with
* the positional values. Switch to MemoryImpl view to do copyTo.
*/
@@ -297,7 +304,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final void putBoolean(final long offsetBytes, final boolean value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -325,7 +334,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
@Override
public final void putByte(final long offsetBytes, final byte value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putByte(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -352,7 +363,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final void putNativeOrderedChar(final long offsetBytes, final char value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putChar(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -363,7 +376,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final void putNativeOrderedInt(final long offsetBytes, final int value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_INT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_INT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putInt(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -374,7 +389,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final void putNativeOrderedLong(final long offsetBytes, final long value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putLong(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -385,7 +402,9 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
}
final void putNativeOrderedShort(final long offsetBytes, final short value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_SHORT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putShort(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
index 789be9a..d734742 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/BaseWritableMemoryImpl.java
@@ -167,7 +167,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
negativeCheck(offsetBytes, "offsetBytes must be >= 0");
negativeCheck(capacityBytes, "capacityBytes must be >= 0");
Objects.requireNonNull(byteOrder, "byteOrder must be non-null.");
- checkValidAndBounds(offsetBytes, capacityBytes);
+ checkValid();
+ checkBounds(offsetBytes, capacityBytes, capacityBytes_);
final boolean readOnly = isReadOnly() || localReadOnly;
return toWritableRegion(offsetBytes, capacityBytes, readOnly, byteOrder);
}
@@ -203,7 +204,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
//PRIMITIVE getX() and getXArray()
@Override
public final boolean getBoolean(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE, capacityBytes_);
return unsafe.getBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -211,7 +213,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
public final void getBooleanArray(final long offsetBytes, final boolean[] dstArray,
final int dstOffsetBooleans, final int lengthBooleans) {
final long copyBytes = lengthBooleans;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetBooleans, lengthBooleans, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -223,7 +226,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final byte getByte(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
return unsafe.getByte(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -231,7 +235,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
public final void getByteArray(final long offsetBytes, final byte[] dstArray,
final int dstOffsetBytes, final int lengthBytes) {
final long copyBytes = lengthBytes;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetBytes, lengthBytes, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -244,8 +249,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final int getCharsFromUtf8(final long offsetBytes, final int utf8LengthBytes,
final Appendable dst) throws IOException, Utf8CodingException {
- checkValidAndBounds(offsetBytes, utf8LengthBytes);
- return Utf8.getCharsFromUtf8(offsetBytes, utf8LengthBytes, dst, getCumulativeOffset(),
+ checkValid();
+ checkBounds(offsetBytes, utf8LengthBytes, capacityBytes_);
+ return Utf8.getCharsFromUtf8(offsetBytes, utf8LengthBytes, dst, getCumulativeOffset(0),
getUnsafeObject());
}
@@ -263,22 +269,26 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
//PRIMITIVE getX() Native Endian (used by both endians)
final char getNativeOrderedChar(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE, capacityBytes_);
return unsafe.getChar(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
final int getNativeOrderedInt(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_INT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_INT_INDEX_SCALE, capacityBytes_);
return unsafe.getInt(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
final long getNativeOrderedLong(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
return unsafe.getLong(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
final short getNativeOrderedShort(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE, capacityBytes_);
return unsafe.getShort(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -300,7 +310,8 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void writeTo(final long offsetBytes, final long lengthBytes,
final WritableByteChannel out) throws IOException {
- checkValidAndBounds(offsetBytes, lengthBytes);
+ checkValid();
+ checkBounds(offsetBytes, lengthBytes, capacityBytes_);
if (getUnsafeObject() instanceof byte[]) {
writeByteArrayTo((byte[]) getUnsafeObject(), offsetBytes, lengthBytes, out);
} else if (getUnsafeObject() == null) {
@@ -315,7 +326,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
//PRIMITIVE putX() and putXArray() implementations
@Override
public final void putBoolean(final long offsetBytes, final boolean value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BOOLEAN_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putBoolean(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -323,7 +336,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
public final void putBooleanArray(final long offsetBytes, final boolean[] srcArray,
final int srcOffsetBooleans, final int lengthBooleans) {
final long copyBytes = lengthBooleans;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetBooleans, lengthBooleans, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -336,7 +351,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void putByte(final long offsetBytes, final byte value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putByte(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -344,7 +361,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
public final void putByteArray(final long offsetBytes, final byte[] srcArray,
final int srcOffsetBytes, final int lengthBytes) {
final long copyBytes = lengthBytes;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetBytes, lengthBytes, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -358,28 +377,36 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final long putCharsToUtf8(final long offsetBytes, final CharSequence src) {
checkValid();
- return Utf8.putCharsToUtf8(offsetBytes, src, getCapacity(), getCumulativeOffset(),
+ return Utf8.putCharsToUtf8(offsetBytes, src, getCapacity(), getCumulativeOffset(0),
getUnsafeObject());
}
//PRIMITIVE putX() Native Endian (used by both endians)
final void putNativeOrderedChar(final long offsetBytes, final char value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_CHAR_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_CHAR_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putChar(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
final void putNativeOrderedInt(final long offsetBytes, final int value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_INT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_INT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putInt(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
final void putNativeOrderedLong(final long offsetBytes, final long value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putLong(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
final void putNativeOrderedShort(final long offsetBytes, final short value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_SHORT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_SHORT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putShort(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -408,7 +435,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void clearBits(final long offsetBytes, final byte bitMask) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long cumBaseOff = getCumulativeOffset(offsetBytes);
int value = unsafe.getByte(getUnsafeObject(), cumBaseOff) & 0XFF;
value &= ~bitMask;
@@ -422,7 +451,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void fill(long offsetBytes, long lengthBytes, final byte value) {
- checkValidBoundsWritable(offsetBytes, lengthBytes);
+ checkValid();
+ checkBounds(offsetBytes, lengthBytes, capacityBytes_);
+ checkWritable();
while (lengthBytes > 0) {
final long chunk = Math.min(lengthBytes, Util.UNSAFE_COPY_THRESHOLD_BYTES);
unsafe.setMemory(getUnsafeObject(), getCumulativeOffset(offsetBytes), chunk, value);
@@ -433,7 +464,9 @@ public abstract class BaseWritableMemoryImpl extends BaseStateImpl implements Wr
@Override
public final void setBits(final long offsetBytes, final byte bitMask) {
- checkValidBoundsWritable(offsetBytes, ARRAY_BYTE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long myOffset = getCumulativeOffset(offsetBytes);
final byte value = unsafe.getByte(getUnsafeObject(), myOffset);
unsafe.putByte(getUnsafeObject(), myOffset, (byte)(value | bitMask));
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
index 1e595ca..bae8609 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableBufferImpl.java
@@ -67,9 +67,9 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
@@ -77,9 +77,9 @@ final class DirectNonNativeWritableBufferImpl extends NonNativeWritableBufferImp
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
index 616c13d..6a5cc24 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectNonNativeWritableMemoryImpl.java
@@ -67,9 +67,9 @@ final class DirectNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImp
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
index 768bf4d..e8fbf71 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableBufferImpl.java
@@ -67,9 +67,9 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
@@ -77,9 +77,9 @@ final class DirectWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
index 4f5c951..fde58fe 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/DirectWritableMemoryImpl.java
@@ -67,9 +67,9 @@ final class DirectWritableMemoryImpl extends NativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new DirectWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr)
: new DirectNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid, memReqSvr);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
index 1a324f7..5ace2ae 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableBufferImpl.java
@@ -64,9 +64,9 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
@@ -74,9 +74,9 @@ final class HeapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableMemoryImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableMemoryImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
index 91702c5..2723574 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapNonNativeWritableMemoryImpl.java
@@ -64,9 +64,9 @@ final class HeapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
index 033ad87..439d0e4 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableBufferImpl.java
@@ -64,9 +64,9 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
@@ -74,9 +74,9 @@ final class HeapWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableMemoryImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableMemoryImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
index d2f05d9..ce56fde 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/HeapWritableMemoryImpl.java
@@ -64,9 +64,9 @@ final class HeapWritableMemoryImpl extends NativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new HeapWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr)
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr)
: new HeapNonNativeWritableBufferImpl(
- unsafeObj, getRegionOffset(), getCapacity(), type, memReqSvr);
+ unsafeObj, getRegionOffset(0), getCapacity(), type, memReqSvr);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
index 31a4f1f..a0380a0 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableBufferImpl.java
@@ -64,9 +64,9 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new MapWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
@@ -74,9 +74,9 @@ final class MapNonNativeWritableBufferImpl extends NonNativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new MapWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
index 5305e5f..00f9253 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapNonNativeWritableMemoryImpl.java
@@ -64,9 +64,9 @@ final class MapNonNativeWritableMemoryImpl extends NonNativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new MapWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
index 9f7c35c..ecccfc9 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableBufferImpl.java
@@ -64,9 +64,9 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly) | DUPLICATE;
return Util.isNativeByteOrder(byteOrder)
? new MapWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
@@ -74,9 +74,9 @@ final class MapWritableBufferImpl extends NativeWritableBufferImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new MapWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableMemoryImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
index 184c1a6..6cfe5c0 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/MapWritableMemoryImpl.java
@@ -64,9 +64,9 @@ final class MapWritableMemoryImpl extends NativeWritableMemoryImpl {
final int type = setReadOnlyType(typeId, readOnly);
return Util.isNativeByteOrder(byteOrder)
? new MapWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid)
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid)
: new MapNonNativeWritableBufferImpl(
- nativeBaseOffset, getRegionOffset(), getCapacity(), type, valid);
+ nativeBaseOffset, getRegionOffset(0), getCapacity(), type, valid);
}
@Override
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
index b8f92ec..2d10857 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableBufferImpl.java
@@ -79,7 +79,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public double getDouble(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
return unsafe.getDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -107,7 +108,8 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public float getFloat(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
return unsafe.getFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -233,7 +235,9 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public void putDouble(final long offsetBytes, final double value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -261,7 +265,9 @@ abstract class NativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public void putFloat(final long offsetBytes, final float value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
index 52ef867..8586d97 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImpl.java
@@ -56,7 +56,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getCharArray(final long offsetBytes, final char[] dstArray, final int dstOffsetChars,
final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetChars, lengthChars, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -68,7 +69,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public double getDouble(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
return unsafe.getDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -76,7 +78,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getDoubleArray(final long offsetBytes, final double[] dstArray,
final int dstOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetDoubles, lengthDoubles, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -88,7 +91,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public float getFloat(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
return unsafe.getFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -96,7 +100,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getFloatArray(final long offsetBytes, final float[] dstArray,
final int dstOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetFloats, lengthFloats, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -115,7 +120,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getIntArray(final long offsetBytes, final int[] dstArray, final int dstOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetInts, lengthInts, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -134,7 +140,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getLongArray(final long offsetBytes, final long[] dstArray,
final int dstOffsetLongs, final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetLongs, lengthLongs, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -153,7 +160,8 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getShortArray(final long offsetBytes, final short[] dstArray,
final int dstOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
checkBounds(dstOffsetShorts, lengthShorts, dstArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
getUnsafeObject(),
@@ -173,7 +181,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putCharArray(final long offsetBytes, final char[] srcArray,
final int srcOffsetChars, final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetChars, lengthChars, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -186,7 +196,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public void putDouble(final long offsetBytes, final double value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putDouble(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -194,7 +206,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putDoubleArray(final long offsetBytes, final double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetDoubles, lengthDoubles, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -207,7 +221,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public void putFloat(final long offsetBytes, final float value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putFloat(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
@@ -215,7 +231,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putFloatArray(final long offsetBytes, final float[] srcArray,
final int srcOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetFloats, lengthFloats, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -235,7 +253,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putIntArray(final long offsetBytes, final int[] srcArray, final int srcOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetInts, lengthInts, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -255,7 +275,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putLongArray(final long offsetBytes, final long[] srcArray, final int srcOffsetLongs,
final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetLongs, lengthLongs, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -275,7 +297,9 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putShortArray(final long offsetBytes, final short[] srcArray,
final int srcOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
checkBounds(srcOffsetShorts, lengthShorts, srcArray.length);
CompareAndCopy.copyMemoryCheckingDifferentObject(
srcArray,
@@ -289,21 +313,27 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
//Atomic Write Methods
@Override
public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long addr = getCumulativeOffset(offsetBytes);
return unsafe.getAndAddLong(getUnsafeObject(), addr, delta);
}
@Override
public long getAndSetLong(final long offsetBytes, final long newValue) { //JDK 8+
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long addr = getCumulativeOffset(offsetBytes);
return unsafe.getAndSetLong(getUnsafeObject(), addr, newValue);
}
@Override
public boolean compareAndSwapLong(final long offsetBytes, final long expect, final long update) {
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
return unsafe.compareAndSwapLong(
getUnsafeObject(), getCumulativeOffset(offsetBytes), expect, update);
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
index ce18109..fe8a04d 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableBufferImpl.java
@@ -69,7 +69,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public double getDouble(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
return Double.longBitsToDouble(
Long.reverseBytes(unsafe.getLong(getUnsafeObject(), getCumulativeOffset(offsetBytes))));
}
@@ -94,7 +95,8 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public float getFloat(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
return Float.intBitsToFloat(
Integer.reverseBytes(unsafe.getInt(getUnsafeObject(), getCumulativeOffset(offsetBytes))));
}
@@ -197,7 +199,9 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public void putDouble(final long offsetBytes, final double value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putLong(getUnsafeObject(), getCumulativeOffset(offsetBytes),
Long.reverseBytes(Double.doubleToRawLongBits(value)));
}
@@ -222,7 +226,9 @@ abstract class NonNativeWritableBufferImpl extends BaseWritableBufferImpl {
@Override
public void putFloat(final long offsetBytes, final float value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putInt(getUnsafeObject(), getCumulativeOffset(offsetBytes),
Integer.reverseBytes(Float.floatToRawIntBits(value)));
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
index 894dd79..1d5cbda 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImpl.java
@@ -34,7 +34,7 @@ import org.apache.datasketches.memory.WritableMemory;
@SuppressWarnings("restriction")
abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
- //Pass-through ctor
+ //Pass-through constructor
NonNativeWritableMemoryImpl(final Object unsafeObj, final long nativeBaseOffset,
final long regionOffset, final long capacityBytes) {
super(unsafeObj, nativeBaseOffset, regionOffset, capacityBytes);
@@ -50,14 +50,16 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getCharArray(final long offsetBytes, final char[] dstArray, final int dstOffsetChars,
final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeChars(getUnsafeObject(), getCumulativeOffset(offsetBytes),
copyBytes, dstArray, dstOffsetChars, lengthChars);
}
@Override
public double getDouble(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
return Double.longBitsToDouble(
Long.reverseBytes(unsafe.getLong(getUnsafeObject(), getCumulativeOffset(offsetBytes))));
}
@@ -66,14 +68,16 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getDoubleArray(final long offsetBytes, final double[] dstArray,
final int dstOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeDoubles(getUnsafeObject(), getCumulativeOffset(offsetBytes),
copyBytes, dstArray, dstOffsetDoubles, lengthDoubles);
}
@Override
public float getFloat(final long offsetBytes) {
- checkValidAndBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
return Float.intBitsToFloat(
Integer.reverseBytes(unsafe.getInt(getUnsafeObject(), getCumulativeOffset(offsetBytes))));
}
@@ -82,7 +86,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getFloatArray(final long offsetBytes, final float[] dstArray,
final int dstOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeFloats(getUnsafeObject(), getCumulativeOffset(offsetBytes),
copyBytes, dstArray, dstOffsetFloats, lengthFloats);
}
@@ -96,7 +101,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getIntArray(final long offsetBytes, final int[] dstArray, final int dstOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeInts(getUnsafeObject(), getCumulativeOffset(offsetBytes), copyBytes,
dstArray, dstOffsetInts, lengthInts);
}
@@ -110,7 +116,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getLongArray(final long offsetBytes, final long[] dstArray,
final int dstOffsetLongs, final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeLongs(getUnsafeObject(), getCumulativeOffset(offsetBytes), copyBytes,
dstArray, dstOffsetLongs, lengthLongs);
}
@@ -124,7 +131,8 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void getShortArray(final long offsetBytes, final short[] dstArray,
final int dstOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- checkValidAndBounds(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
CompareAndCopy.getNonNativeShorts(getUnsafeObject(), getCumulativeOffset(offsetBytes),
copyBytes, dstArray, dstOffsetShorts, lengthShorts);
}
@@ -139,14 +147,18 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putCharArray(final long offsetBytes, final char[] srcArray, final int srcOffsetChars,
final int lengthChars) {
final long copyBytes = ((long) lengthChars) << CHAR_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeChars(srcArray, srcOffsetChars, lengthChars, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@Override
public void putDouble(final long offsetBytes, final double value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_DOUBLE_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putLong(getUnsafeObject(), getCumulativeOffset(offsetBytes),
Long.reverseBytes(Double.doubleToRawLongBits(value)));
}
@@ -155,14 +167,18 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putDoubleArray(final long offsetBytes, final double[] srcArray,
final int srcOffsetDoubles, final int lengthDoubles) {
final long copyBytes = ((long) lengthDoubles) << DOUBLE_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeDoubles(srcArray, srcOffsetDoubles, lengthDoubles, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@Override
public void putFloat(final long offsetBytes, final float value) {
- checkValidBoundsWritable(offsetBytes, ARRAY_FLOAT_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_FLOAT_INDEX_SCALE, capacityBytes_);
+ checkWritable();
unsafe.putInt(getUnsafeObject(), getCumulativeOffset(offsetBytes),
Integer.reverseBytes(Float.floatToRawIntBits(value)));
}
@@ -171,7 +187,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putFloatArray(final long offsetBytes, final float[] srcArray,
final int srcOffsetFloats, final int lengthFloats) {
final long copyBytes = ((long) lengthFloats) << FLOAT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeFloats(srcArray, srcOffsetFloats, lengthFloats, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -185,7 +203,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putIntArray(final long offsetBytes, final int[] srcArray, final int srcOffsetInts,
final int lengthInts) {
final long copyBytes = ((long) lengthInts) << INT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeInts(srcArray, srcOffsetInts, lengthInts, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -199,7 +219,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putLongArray(final long offsetBytes, final long[] srcArray, final int srcOffsetLongs,
final int lengthLongs) {
final long copyBytes = ((long) lengthLongs) << LONG_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeLongs(srcArray, srcOffsetLongs, lengthLongs, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -213,7 +235,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
public void putShortArray(final long offsetBytes, final short[] srcArray,
final int srcOffsetShorts, final int lengthShorts) {
final long copyBytes = ((long) lengthShorts) << SHORT_SHIFT;
- checkValidBoundsWritable(offsetBytes, copyBytes);
+ checkValid();
+ checkBounds(offsetBytes, copyBytes, capacityBytes_);
+ checkWritable();
CompareAndCopy.putNonNativeShorts(srcArray, srcOffsetShorts, lengthShorts, copyBytes,
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
@@ -221,7 +245,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
//Atomic Write Methods
@Override
public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long addr = getCumulativeOffset(offsetBytes);
long oldValReverseBytes, oldVal, newValReverseBytes;
final Object unsafeObj = getUnsafeObject();
@@ -236,7 +262,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public long getAndSetLong(final long offsetBytes, final long newValue) { //JDK 8+
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
final long addr = getCumulativeOffset(offsetBytes);
final long newValueReverseBytes = Long.reverseBytes(newValue);
return Long.reverseBytes(unsafe.getAndSetLong(getUnsafeObject(), addr, newValueReverseBytes));
@@ -244,7 +272,9 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
@Override
public boolean compareAndSwapLong(final long offsetBytes, final long expect, final long update) {
- checkValidBoundsWritable(offsetBytes, ARRAY_LONG_INDEX_SCALE);
+ checkValid();
+ checkBounds(offsetBytes, ARRAY_LONG_INDEX_SCALE, capacityBytes_);
+ checkWritable();
return unsafe.compareAndSwapLong(getUnsafeObject(), getCumulativeOffset(offsetBytes),
Long.reverseBytes(expect), Long.reverseBytes(update));
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
index a054ef9..130bc7d 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
@@ -21,7 +21,6 @@ package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.BaseStateImpl.NATIVE_BYTE_ORDER;
import static org.apache.datasketches.memory.internal.BaseStateImpl.checkJavaVersion;
-import static org.apache.datasketches.memory.internal.BaseStateImpl.isNativeByteOrder;
import static org.apache.datasketches.memory.internal.BaseStateImpl.parseJavaVersion;
import static org.apache.datasketches.memory.internal.BaseStateImpl.typeDecode;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_INDEX_SCALE;
@@ -157,15 +156,6 @@ public class BaseStateTest {
fail();
}
- @Test
- public void checkIsNativeByteOrder() {
- assertTrue(isNativeByteOrder(NATIVE_BYTE_ORDER));
- try {
- isNativeByteOrder(null);
- fail();
- } catch (final IllegalArgumentException e) {}
- }
-
@Test
public void checkXxHash64() {
WritableMemory mem = WritableMemory.allocate(8);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
index e94f384..abf330a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
@@ -54,7 +54,6 @@ public class Buffer2Test {
assertEquals(bb.get(), buffer.getByte());
}
- assertEquals(true, buffer.hasArray());
assertEquals(true, buffer.hasByteBuffer());
}
@@ -73,8 +72,6 @@ public class Buffer2Test {
while (buffer.hasRemaining()) {
assertEquals(bb.get(), buffer.getByte());
}
-
- assertEquals(false, buffer.hasArray());
assertEquals(true, buffer.hasByteBuffer());
}
@@ -97,7 +94,6 @@ public class Buffer2Test {
buffer.getByteArray(copyByteArray, 0, 64);
assertEquals(byteArray, copyByteArray);
- assertEquals(true, buffer.hasArray());
assertEquals(false, buffer.hasByteBuffer());
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
index 34d341c..614b10a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferTest.java
@@ -281,7 +281,7 @@ public class BufferTest {
}
}
- @Test//(expectedExceptions = IllegalStateException.class)
+ @Test(expectedExceptions = IllegalStateException.class)
public void checkParentUseAfterFree() throws Exception {
int bytes = 64 * 8;
WritableHandle wh = WritableMemory.allocateDirect(bytes);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
index fec0387..51bfb5a 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/LeafImplTest.java
@@ -182,7 +182,7 @@ public class LeafImplTest {
assertEquals(mem.asWritableBuffer(bo).getShort(0), 1);
assertEquals(mem.asWritableBuffer(oo).getShort(0), 256);
- ByteBuffer bb = mem.getByteBuffer();
+ ByteBuffer bb = ((BaseStateImpl)mem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
assertTrue(mem.getByteOrder() == bo);
@@ -207,7 +207,7 @@ public class LeafImplTest {
assertEquals(buf.writableDuplicate(bo).getShort(0), 1);
assertEquals(buf.writableDuplicate(oo).getShort(0), 256);
- bb = buf.getByteBuffer();
+ bb = ((BaseStateImpl)buf).getByteBuffer();
assertTrue(hasByteBuffer ? bb != null : bb == null);
assertTrue(buf.getByteOrder() == bo);
@@ -232,7 +232,7 @@ public class LeafImplTest {
assertEquals(nnMem.asWritableBuffer(bo).getShort(0), 1);
assertEquals(nnMem.asWritableBuffer(oo).getShort(0), 256);
- bb = nnMem.getByteBuffer();
+ bb = ((BaseStateImpl)nnMem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
assertTrue(nnMem.getByteOrder() == oo);
@@ -257,7 +257,7 @@ public class LeafImplTest {
assertEquals(nnBuf.writableDuplicate(bo).getShort(0), 1);
assertEquals(nnBuf.writableDuplicate(oo).getShort(0), 256);
- bb = nnBuf.getByteBuffer();
+ bb = ((BaseStateImpl)nnBuf).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
assertTrue(nnBuf.getByteOrder() == oo);
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
index 0f242d4..7504b62 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MemoryTest.java
@@ -386,13 +386,6 @@ public class MemoryTest {
}
}
- @Test
- public void checkHashCode() {
- WritableMemory wmem = WritableMemory.allocate(32 + 7);
- int hc = wmem.hashCode();
- assertEquals(hc, -1895166923);
- }
-
@Test
public void checkSelfEqualsToAndCompareTo() {
int len = 64;
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v2Test.java
deleted file mode 100644
index 6949008..0000000
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v2Test.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.datasketches.memory.internal;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.datasketches.memory.MurmurHash3v2.hash;
-import static org.testng.Assert.fail;
-
-import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.MurmurHash3v2;
-import org.apache.datasketches.memory.WritableHandle;
-import org.apache.datasketches.memory.WritableMemory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * Tests the MurmurHash3 against specific, known hash results given known
- * inputs obtained from the public domain C++ version 150.
- *
- * @author Lee Rhodes
- */
-public class MurmurHash3v2Test {
-
- @Test
- public void checkByteArrRemainderGT8() { //byte[], remainder > 8
- String keyStr = "The quick brown fox jumps over the lazy dog";
- byte[] key = keyStr.getBytes(UTF_8);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xe34bbc7bbc071b6cL;
- long h2 = 0x7a433ca9c49a9347L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- @Test
- public void checkByteArrChange1bit() { //byte[], change one bit
- String keyStr = "The quick brown fox jumps over the lazy eog";
- byte[] key = keyStr.getBytes(UTF_8);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0x362108102c62d1c9L;
- long h2 = 0x3285cd100292b305L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- @Test
- public void checkByteArrRemainderLt8() { //byte[], test a remainder < 8
- String keyStr = "The quick brown fox jumps over the lazy dogdogdog";
- byte[] key = keyStr.getBytes(UTF_8);
- long[] result = hash(key, 0);
- //Should be;
- long h1 = 0x9c8205300e612fc4L;
- long h2 = 0xcbc0af6136aa3df9L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- @Test
- public void checkByteArrReaminderEQ8() { //byte[], test a remainder = 8
- String keyStr = "The quick brown fox jumps over the lazy1";
- byte[] key = keyStr.getBytes(UTF_8);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xe3301a827e5cdfe3L;
- long h2 = 0xbdbf05f8da0f0392L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
-
- }
-
- /**
- * This test should have the exact same output as Test4
- */
- @Test
- public void checkLongArrRemainderEQ8() { //long[], test a remainder = 8
- String keyStr = "The quick brown fox jumps over the lazy1";
- long[] key = stringToLongs(keyStr);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xe3301a827e5cdfe3L;
- long h2 = 0xbdbf05f8da0f0392L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
-
- }
-
- /**
- * This test should have the exact same output as Test4
- */
- @Test
- public void checkIntArrRemainderEQ8() { //int[], test a remainder = 8
- String keyStr = "The quick brown fox jumps over the lazy1"; //40B
- int[] key = stringToInts(keyStr);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xe3301a827e5cdfe3L;
- long h2 = 0xbdbf05f8da0f0392L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- @Test
- public void checkIntArrRemainderEQ0() { //int[], test a remainder = 0
- String keyStr = "The quick brown fox jumps over t"; //32B
- int[] key = stringToInts(keyStr);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xdf6af91bb29bdacfL;
- long h2 = 0x91a341c58df1f3a6L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
-
- /**
- * Tests an odd remainder of int[].
- */
- @Test
- public void checkIntArrOddRemainder() { //int[], odd remainder
- String keyStr = "The quick brown fox jumps over the lazy dog"; //43B
- int[] key = stringToInts(keyStr);
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0x1eb232b0087543f5L;
- long h2 = 0xfc4c1383c3ace40fL;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
-
- /**
- * Tests an odd remainder of int[].
- */
- @Test
- public void checkCharArrOddRemainder() { //char[], odd remainder
- String keyStr = "The quick brown fox jumps over the lazy dog.."; //45B
- char[] key = keyStr.toCharArray();
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0xca77b498ea9ed953L;
- long h2 = 0x8b8f8ec3a8f4657eL;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- /**
- * Tests an odd remainder of int[].
- */
- @Test
- public void checkCharArrRemainderEQ0() { //char[], remainder of 0
- String keyStr = "The quick brown fox jumps over the lazy "; //40B
- char[] key = keyStr.toCharArray();
- long[] result = hash(key, 0);
- //Should be:
- long h1 = 0x51b15e9d0887f9f1L;
- long h2 = 0x8106d226786511ebL;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- @Test
- public void checkByteArrAllOnesZeros() { //byte[], test a ones byte and a zeros byte
- byte[] key = {
- 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e,
- 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65,
- 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67,
- (byte) 0xff, 0x64, 0x6f, 0x67, 0x00
- };
- long[] result = MurmurHash3v2.hash(key, 0);
-
- //Should be:
- long h1 = 0xe88abda785929c9eL;
- long h2 = 0x96b98587cacc83d6L;
- Assert.assertEquals(result[0], h1);
- Assert.assertEquals(result[1], h2);
- }
-
- /**
- * This test demonstrates that the hash of byte[], char[], int[], or long[] will produce the
- * same hash result if, and only if, all the arrays have the same exact length in bytes, and if
- * the contents of the values in the arrays have the same byte endianness and overall order.
- */
- @Test
- public void checkCrossTypeHashConsistency() {
- long[] out;
- println("Bytes");
- byte[] bArr = {1,2,3,4,5,6,7,8, 9,10,11,12,13,14,15,16, 17,18,19,20,21,22,23,24};
- long[] out1 = hash(bArr, 0L);
- println(longToHexBytes(out1[0]));
- println(longToHexBytes(out1[1]));
-
- println("Chars");
- char[] cArr = {0X0201, 0X0403, 0X0605, 0X0807, 0X0a09, 0X0c0b, 0X0e0d, 0X100f,
- 0X1211, 0X1413, 0X1615, 0X1817};
- out = hash(cArr, 0L);
- Assert.assertEquals(out, out1);
- println(longToHexBytes(out[0]));
- println(longToHexBytes(out[1]));
-
- println("Ints");
- int[] iArr = {0X04030201, 0X08070605, 0X0c0b0a09, 0X100f0e0d, 0X14131211, 0X18171615};
- out = hash(iArr, 0L);
- Assert.assertEquals(out, out1);
- println(longToHexBytes(out[0]));
- println(longToHexBytes(out[1]));
-
- println("Longs");
- long[] lArr = {0X0807060504030201L, 0X100f0e0d0c0b0a09L, 0X1817161514131211L};
- out = hash(lArr, 0L);
- Assert.assertEquals(out, out1);
- println(longToHexBytes(out[0]));
- println(longToHexBytes(out[1]));
- }
-
- @Test
- public void checkEmptyOrNullExceptions() {
- try {
- long[] arr = null; hash(arr, 1L); fail();
- } catch (final IllegalArgumentException e) { }
- try {
- int[] arr = null; hash(arr, 1L); fail();
- } catch (final IllegalArgumentException e) { }
- try {
- char[] arr = null; hash(arr, 1L); fail();
- } catch (final IllegalArgumentException e) { }
- try {
- byte[] arr = null; hash(arr, 1L); fail();
- } catch (final IllegalArgumentException e) { }
- try {
- long[] out = new long[2];
- String in = null; hash(in, 1L, out); fail();
- } catch (final IllegalArgumentException e) { }
- try {
- long[] out = new long[2];
- Memory mem = Memory.wrap(new byte[0]);
- out = hash(mem, 0L, 4L, 1L, out);
- } catch (final IllegalArgumentException e) { }
- try (WritableHandle wh = WritableMemory.allocateDirect(8)) {
- long[] out = new long[2];
- Memory mem = wh.get();
- out = hash(mem, 0L, 4L, 1L, out);
- } catch (Exception ee) {}
- }
-
- @Test
- public void checkHashTails() {
- long[] out = new long[2];
- WritableMemory mem = WritableMemory.allocate(32);
- mem.fill((byte)85);
-
- for (int i = 16; i <= 32; i++) {
- out = hash(mem, 0, i, 1L, out);
- }
- }
-
- @Test
- public void checkSinglePrimitives() {
- long[] out = new long[2];
- out = hash(1L, 1L, out);
- out = hash(0.0, 1L, out);
- out = hash("123", 1L, out);
- }
-
- //Helper methods
-
- private static long[] stringToLongs(String in) {
- byte[] bArr = in.getBytes(UTF_8);
- int inLen = bArr.length;
- int outLen = (inLen / 8) + (((inLen % 8) != 0) ? 1 : 0);
- long[] out = new long[outLen];
-
- for (int i = 0; i < (outLen - 1); i++ ) {
- for (int j = 0; j < 8; j++ ) {
- out[i] |= ((bArr[(i * 8) + j] & 0xFFL) << (j * 8));
- }
- }
- int inTail = 8 * (outLen - 1);
- int rem = inLen - inTail;
- for (int j = 0; j < rem; j++ ) {
- out[outLen - 1] |= ((bArr[inTail + j] & 0xFFL) << (j * 8));
- }
- return out;
- }
-
- private static int[] stringToInts(String in) {
- byte[] bArr = in.getBytes(UTF_8);
- int inLen = bArr.length;
- int outLen = (inLen / 4) + (((inLen % 4) != 0) ? 1 : 0);
- int[] out = new int[outLen];
-
- for (int i = 0; i < (outLen - 1); i++ ) {
- for (int j = 0; j < 4; j++ ) {
- out[i] |= ((bArr[(i * 4) + j] & 0xFFL) << (j * 8));
- }
- }
- int inTail = 4 * (outLen - 1);
- int rem = inLen - inTail;
- for (int j = 0; j < rem; j++ ) {
- out[outLen - 1] |= ((bArr[inTail + j] & 0xFFL) << (j * 8));
- }
- return out;
- }
-
- /**
- * Returns a string of spaced hex bytes in Big-Endian order.
- * @param v the given long
- * @return string of spaced hex bytes in Big-Endian order.
- */
- private static String longToHexBytes(final long v) {
- final long mask = 0XFFL;
- final StringBuilder sb = new StringBuilder();
- for (int i = 8; i-- > 0; ) {
- final String s = Long.toHexString((v >>> (i * 8)) & mask);
- sb.append(zeroPad(s, 2)).append(" ");
- }
- return sb.toString();
- }
-
- /**
- * Prepend the given string with zeros. If the given string is equal or greater than the given
- * field length, it will be returned without modification.
- * @param s the given string
- * @param fieldLength desired total field length including the given string
- * @return the given string prepended with zeros.
- */
- private static final String zeroPad(final String s, final int fieldLength) {
- return characterPad(s, fieldLength, '0', false);
- }
-
- /**
- * Prepend or postpend the given string with the given character to fill the given field length.
- * If the given string is equal or greater than the given field length, it will be returned
- * without modification.
- * @param s the given string
- * @param fieldLength the desired field length
- * @param padChar the desired pad character
- * @param postpend if true append the padCharacters to the end of the string.
- * @return prepended or postpended given string with the given character to fill the given field
- * length.
- */
- private static final String characterPad(final String s, final int fieldLength, final char padChar,
- final boolean postpend) {
- final char[] chArr = s.toCharArray();
- final int sLen = chArr.length;
- if (sLen < fieldLength) {
- final char[] out = new char[fieldLength];
- final int blanks = fieldLength - sLen;
-
- if (postpend) {
- for (int i = 0; i < sLen; i++) {
- out[i] = chArr[i];
- }
- for (int i = sLen; i < fieldLength; i++) {
- out[i] = padChar;
- }
- } else { //prepend
- for (int i = 0; i < blanks; i++) {
- out[i] = padChar;
- }
- for (int i = blanks; i < fieldLength; i++) {
- out[i] = chArr[i - blanks];
- }
- }
-
- return String.valueOf(out);
- }
- return s;
- }
-
- @Test
- public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
- }
-
- /**
- * @param s value to print
- */
- static void println(String s) {
- //System.out.println(s); //disable here
- }
-
-}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
index e6ce014..75cac3b 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableBufferImplTest.java
@@ -76,7 +76,7 @@ public class NativeWritableBufferImplTest {
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- assertTrue(buf.hasArray());
+ assertFalse(buf.isDirect());
}
@Test
@@ -258,7 +258,7 @@ public class NativeWritableBufferImplTest {
}
assertTrue(wbuf.hasByteBuffer());
- ByteBuffer byteBuf2 = wbuf.getByteBuffer();
+ ByteBuffer byteBuf2 = ((BaseStateImpl)wbuf).getByteBuffer();
assertEquals(byteBuf2, byteBuf);
//println( mem.toHexString("HeapBB", 0, memCapacity));
}
@@ -458,7 +458,7 @@ public class NativeWritableBufferImplTest {
for (int i = 0; i < 64; i++) { wmem.putByte(i, (byte)i); }
WritableBuffer wbuf = wmem.asWritableBuffer().writableDuplicate();
- wbuf.checkValidAndBounds(0, 64);
+ BaseStateImpl.checkBounds(0, 64, wbuf.getCapacity());
for (int i = 0; i < 64; i++) {
assertEquals(wbuf.getByte(), i);
}
@@ -472,7 +472,7 @@ public class NativeWritableBufferImplTest {
assertEquals(wmem2.getByte(i), i);
}
WritableMemory wmem3 = wbuf.asWritableMemory();
- wmem3.checkValidAndBounds(0, 64);
+ BaseStateImpl.checkBounds(0, 64, wmem3.getCapacity());
}
@Test
@@ -480,10 +480,8 @@ public class NativeWritableBufferImplTest {
WritableMemory wmem = WritableMemory.allocate(64);
WritableMemory reg = wmem.writableRegion(32, 32);
WritableBuffer buf = reg.asWritableBuffer();
- assertEquals(buf.getRegionOffset(), 32);
- assertEquals(buf.getRegionOffset(0), 32);
- assertEquals(buf.getCumulativeOffset(), 32 + 16);
- assertEquals(buf.getCumulativeOffset(0), 32 + 16);
+ assertEquals(((BaseStateImpl)reg).getRegionOffset(0), 32);
+ assertEquals(((BaseStateImpl)buf).getCumulativeOffset(0), 32 + 16);
}
@Test
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
index 3f874dc..df67ef8 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NativeWritableMemoryImplTest.java
@@ -74,7 +74,7 @@ public class NativeWritableMemoryImplTest {
for (int i=0; i<8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- assertTrue(mem.hasArray());
+ assertFalse(mem.isDirect());
}
@Test
@@ -453,7 +453,7 @@ public class NativeWritableMemoryImplTest {
}
assertTrue(wmem.hasByteBuffer());
- ByteBuffer byteBuf2 = wmem.getByteBuffer();
+ ByteBuffer byteBuf2 = ((BaseStateImpl)wmem).getByteBuffer();
assertEquals(byteBuf2, byteBuf);
//println( mem.toHexString("HeapBB", 0, memCapacity));
}
@@ -595,7 +595,7 @@ public class NativeWritableMemoryImplTest {
assertEquals(comp, 0);
comp = mem3.compareTo(0, 4, mem4, 1, 4);
assertEquals(comp, -1);
- mem3.checkValidAndBounds(0, 5);
+ BaseStateImpl.checkBounds(0, 5, mem3. getCapacity());
}
@Test
@@ -658,10 +658,8 @@ public class NativeWritableMemoryImplTest {
public void checkCumAndRegionOffset() {
WritableMemory wmem = WritableMemory.allocate(64);
WritableMemory reg = wmem.writableRegion(32, 32);
- assertEquals(reg.getRegionOffset(), 32);
- assertEquals(reg.getRegionOffset(0), 32);
- assertEquals(reg.getCumulativeOffset(), 32 + 16);
- assertEquals(reg.getCumulativeOffset(0), 32 + 16);
+ assertEquals(((BaseStateImpl)reg).getRegionOffset(0), 32);
+ assertEquals(((BaseStateImpl)reg).getCumulativeOffset(0), 32 + 16);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org