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 2023/02/01 22:48:06 UTC
[datasketches-memory] 01/01: Removed methods that will not be able to be easily replicated using Java 17 Panama
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch removeIncompatibleMethods
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit 994eadbbe9a4b16e56267204bcc08f99d9d0f9f4
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Wed Feb 1 14:47:52 2023 -0800
Removed methods that will not be able to be easily replicated using Java
17 Panama
---
.../apache/datasketches/memory/MurmurHash3v2.java | 361 -------------------
.../org/apache/datasketches/memory/Resource.java | 35 +-
.../apache/datasketches/memory/WritableBuffer.java | 6 +-
.../apache/datasketches/memory/WritableMemory.java | 33 --
.../memory/internal/BaseWritableBufferImpl.java | 10 +-
.../memory/internal/BaseWritableMemoryImpl.java | 8 +-
.../memory/internal/NativeWritableMemoryImpl.java | 23 --
.../internal/NonNativeWritableMemoryImpl.java | 31 --
.../datasketches/memory/internal/ResourceImpl.java | 81 ++---
.../datasketches/memory/internal/Buffer2Test.java | 6 +-
.../memory/internal/BufferBoundaryCheckTest.java | 14 -
.../memory/internal/CommonMemoryTest.java | 26 --
.../datasketches/memory/internal/LeafImplTest.java | 8 +-
.../memory/internal/MurmurHash3v2Test.java | 399 ---------------------
.../internal/NativeWritableBufferImplTest.java | 4 +-
.../internal/NativeWritableMemoryImplTest.java | 4 +-
.../internal/NonNativeWritableMemoryImplTest.java | 37 --
.../memory/internal/WritableMemoryTest.java | 4 +-
18 files changed, 74 insertions(+), 1016 deletions(-)
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 b862571..0000000
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/MurmurHash3v2.java
+++ /dev/null
@@ -1,361 +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;
-
-import org.apache.datasketches.memory.internal.ResourceImpl;
-
-/**
- * <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
- */
-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 = ((ResourceImpl)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/Resource.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
index 591379b..6d87514 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/Resource.java
@@ -20,7 +20,6 @@
package org.apache.datasketches.memory;
import java.io.UncheckedIOException;
-import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
@@ -116,12 +115,6 @@ public interface Resource extends AutoCloseable {
*/
void force();
- /**
- * Gets the backing ByteBuffer if it exists, otherwise returns null.
- * @return the backing ByteBuffer if it exists, otherwise returns null.
- */
- ByteBuffer getByteBuffer(); //TODO Deprecate
-
/**
* Gets the current ByteOrder.
* This may be different from the ByteOrder of the backing resource and {@link ByteOrder#nativeOrder()}
@@ -150,19 +143,6 @@ public interface Resource extends AutoCloseable {
*/
long getTotalOffset();
- /**
- * Returns true if this object is backed by an on-heap primitive array
- * @return true if this object is backed by an on-heap primitive array
- */
- boolean hasArray(); //TODO Change to isHeapResource
-
- /**
- * 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.
- */
- boolean isValid(); //TODO isAlive()
-
/**
* Returns true if this Memory is backed by a ByteBuffer.
* @return true if this Memory is backed by a ByteBuffer.
@@ -193,6 +173,12 @@ public interface Resource extends AutoCloseable {
*/
boolean isDuplicateBufferView();
+ /**
+ * Returns true if this object is backed by an on-heap primitive array
+ * @return true if this object is backed by an on-heap primitive array
+ */
+ boolean isHeapResource();
+
/**
* Tells whether or not the contents of this memory-mapped Resource is resident in physical memory.
*
@@ -239,7 +225,7 @@ public interface Resource extends AutoCloseable {
* Returns true if the backing resource is a memory-mapped file.
* @return true if the backing resource is a memory-mapped file.
*/
- boolean isMapped();
+ boolean isMemoryMappedResource();
/**
* If true, all put and get operations will assume the non-native ByteOrder.
@@ -270,6 +256,13 @@ public interface Resource extends AutoCloseable {
*/
boolean isSameResource(Resource that);
+ /**
+ * 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.
+ */
+ boolean isValid();
+
/**
* Loads the contents of this memory-mapped Resource into physical memory.
*
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
index b6aebe0..027b26a 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableBuffer.java
@@ -364,11 +364,6 @@ public interface WritableBuffer extends Buffer {
// NO ATOMIC METHODS
//OTHER WRITE METHODS
- /**
- * Returns the primitive backing array, otherwise null.
- * @return the primitive backing array, otherwise null.
- */
- Object getArray();
/**
* Clears all bytes of this Buffer from position to end to zero. The position will be set to end.
@@ -405,6 +400,7 @@ public interface WritableBuffer extends Buffer {
* in the test tree.
* @return the MemoryRequestServer object or null.
*/
+ @Override
public MemoryRequestServer getMemoryRequestServer();
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
index bccd2b4..c5cfec6 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/WritableMemory.java
@@ -538,40 +538,7 @@ public interface WritableMemory extends Memory {
*/
void putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts);
- //Atomic Methods
- /**
- * Atomically adds the given value to the long located at offsetBytes.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param delta the amount to add
- * @return the the previous value
- */
- long getAndAddLong(long offsetBytes, long delta);
-
- /**
- * Atomically sets the current value at the memory location to the given updated value
- * if and only if the current value {@code ==} the expected value.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param expect the expected value
- * @param update the new value
- * @return {@code true} if successful. False return indicates that
- * the current value at the memory location was not equal to the expected value.
- */
- boolean compareAndSwapLong(long offsetBytes, long expect, long update);
-
- /**
- * Atomically exchanges the given value with the current value located at offsetBytes.
- * @param offsetBytes offset bytes relative to this Memory start
- * @param newValue new value
- * @return the previous value
- */
- long getAndSetLong(long offsetBytes, long newValue);
-
//OTHER WRITE METHODS
- /**
- * Returns the primitive backing array, otherwise null.
- * @return the primitive backing array, otherwise null.
- */
- Object getArray();
/**
* Clears all bytes of this Memory to zero
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 955d668..438a55f 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
@@ -387,9 +387,13 @@ public abstract class BaseWritableBufferImpl extends BaseBufferImpl implements W
unsafe.putShort(getUnsafeObject(), getCumulativeOffset(offsetBytes), value);
}
- //OTHER
- @Override
- public final Object getArray() {
+ //OTHER WRITE METHODS
+
+ /**
+ * Returns the primitive backing array, otherwise null.
+ * @return the primitive backing array, otherwise null.
+ */
+ final Object getArray() {
checkValid();
return getUnsafeObject();
}
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 e2aee82..a65f889 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
@@ -403,8 +403,12 @@ public abstract class BaseWritableMemoryImpl extends ResourceImpl implements Wri
}
//OTHER WRITE METHODS
- @Override
- public final Object getArray() {
+
+ /**
+ * Returns the primitive backing array, otherwise null.
+ * @return the primitive backing array, otherwise null.
+ */
+ final Object getArray() {
checkValid();
return getUnsafeObject();
}
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 b53d957..922a62d 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
@@ -26,7 +26,6 @@ import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_FLOAT_BAS
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_FLOAT_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_INT_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_LONG_BASE_OFFSET;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_LONG_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_SHORT_BASE_OFFSET;
import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
@@ -283,26 +282,4 @@ abstract class NativeWritableMemoryImpl extends BaseWritableMemoryImpl {
);
}
- //Atomic Write Methods
- @Override
- public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- final long addr = getCumulativeOffset(offsetBytes);
- return unsafe.getAndAddLong(getUnsafeObject(), addr, delta);
- }
-
- @Override
- public long getAndSetLong(final long offsetBytes, final long newValue) { //JDK 8+
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- final long addr = getCumulativeOffset(offsetBytes);
- return unsafe.getAndSetLong(getUnsafeObject(), addr, newValue);
- }
-
- @Override
- public boolean compareAndSwapLong(final long offsetBytes, final long expect, final long update) {
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- return unsafe.compareAndSwapLong(
- getUnsafeObject(), getCumulativeOffset(offsetBytes), expect, update);
- }
-
}
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 ad2133d..8597ce5 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
@@ -21,7 +21,6 @@ package org.apache.datasketches.memory.internal;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_FLOAT_INDEX_SCALE;
-import static org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_LONG_INDEX_SCALE;
import static org.apache.datasketches.memory.internal.UnsafeUtil.unsafe;
import org.apache.datasketches.memory.WritableMemory;
@@ -215,34 +214,4 @@ abstract class NonNativeWritableMemoryImpl extends BaseWritableMemoryImpl {
getUnsafeObject(), getCumulativeOffset(offsetBytes));
}
- //Atomic Write Methods
- @Override
- public long getAndAddLong(final long offsetBytes, final long delta) { //JDK 8+
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- final long addr = getCumulativeOffset(offsetBytes);
- long oldValReverseBytes, oldVal, newValReverseBytes;
- final Object unsafeObj = getUnsafeObject();
- do {
- oldValReverseBytes = unsafe.getLongVolatile(unsafeObj, addr);
- oldVal = Long.reverseBytes(oldValReverseBytes);
- newValReverseBytes = Long.reverseBytes(oldVal + delta);
- } while (!unsafe.compareAndSwapLong(unsafeObj, addr, oldValReverseBytes, newValReverseBytes));
-
- return oldVal;
- }
-
- @Override
- public long getAndSetLong(final long offsetBytes, final long newValue) { //JDK 8+
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- final long addr = getCumulativeOffset(offsetBytes);
- final long newValueReverseBytes = Long.reverseBytes(newValue);
- return Long.reverseBytes(unsafe.getAndSetLong(getUnsafeObject(), addr, newValueReverseBytes));
- }
-
- @Override
- public boolean compareAndSwapLong(final long offsetBytes, final long expect, final long update) {
- checkValidAndBoundsForWrite(offsetBytes, ARRAY_LONG_INDEX_SCALE);
- return unsafe.compareAndSwapLong(getUnsafeObject(), getCumulativeOffset(offsetBytes),
- Long.reverseBytes(expect), Long.reverseBytes(update));
- }
}
diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
index d6411a3..092a567 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/ResourceImpl.java
@@ -115,6 +115,13 @@ public abstract class ResourceImpl implements Resource {
}
}
+ static void checkJavaVersion(final String jdkVer, final int p0, final int p1 ) {
+ final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11);
+ if (!ok) { throw new IllegalArgumentException(
+ "Unsupported JDK Major Version. It must be one of 1.8, 8, 11: " + jdkVer);
+ }
+ }
+
public static final void checkThread(final Thread owner) {
if (owner != Thread.currentThread()) {
throw new IllegalStateException("Attempted access outside owning thread");
@@ -141,14 +148,6 @@ public abstract class ResourceImpl implements Resource {
}
}
- @Override
- public final boolean equals(final Object that) {
- if (this == that) { return true; }
- return that instanceof ResourceImpl
- ? CompareAndCopy.equals(this, (ResourceImpl) that)
- : false;
- }
-
@Override
public final boolean equalTo(final long thisOffsetBytes, final Resource that,
final long thatOffsetBytes, final long lengthBytes) {
@@ -162,11 +161,15 @@ public abstract class ResourceImpl implements Resource {
}
//Overridden by ByteBuffer Leafs
- @Override
- public ByteBuffer getByteBuffer() {
+ ByteBuffer getByteBuffer() {
return null;
}
+ @Override
+ public final ByteOrder getByteOrder() {
+ return isNonNativeType(getTypeId()) ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
+ }
+
/**
* 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
@@ -197,11 +200,6 @@ public abstract class ResourceImpl implements Resource {
//Overridden by ByteBuffer, Direct and Map Leaves
abstract long getNativeBaseOffset();
- @Override
- public final ByteOrder getByteOrder() {
- return isNonNativeType(getTypeId()) ? Util.NON_NATIVE_BYTE_ORDER : ByteOrder.nativeOrder();
- }
-
//Overridden by all leafs
abstract int getTypeId();
@@ -211,17 +209,6 @@ public abstract class ResourceImpl implements Resource {
return null;
}
- @Override
- public final boolean hasArray() {
- checkValid();
- return getUnsafeObject() != null;
- }
-
- @Override
- public final int hashCode() {
- return (int) xxHash64(0, getCapacity(), 0); //xxHash64() calls checkValid()
- }
-
@Override
public boolean isByteBufferResource() {
return (getTypeId() & BYTEBUF) > 0;
@@ -255,6 +242,12 @@ public abstract class ResourceImpl implements Resource {
return (typeId & DUPLICATE) > 0;
}
+ @Override
+ public final boolean isHeapResource() {
+ checkValid();
+ return getUnsafeObject() != null;
+ }
+
final boolean isHeapType(final int typeId) {
return (typeId & (MAP | DIRECT)) == 0;
}
@@ -265,7 +258,7 @@ public abstract class ResourceImpl implements Resource {
}
@Override
- public boolean isMapped() {
+ public boolean isMemoryMappedResource() {
return (getTypeId() & MAP) > 0;
}
@@ -314,21 +307,6 @@ public abstract class ResourceImpl implements Resource {
return (typeId & REGION) > 0;
}
- final boolean isWritableType(final int typeId) { //not used
- return (typeId & READONLY) == 0;
- }
-
- @Override
- public void load() { //overridden by Map leafs
- throw new IllegalStateException("This resource is not a memory-mapped file type.");
- }
-
- final static int removeNnBuf(final int typeId) { return typeId & ~NONNATIVE & ~BUFFER; }
-
- final static int setReadOnlyType(final int typeId, final boolean readOnly) {
- return readOnly ? typeId | READONLY : typeId & ~READONLY;
- }
-
@Override
public boolean isSameResource(final Resource that) {
checkValid();
@@ -336,7 +314,6 @@ public abstract class ResourceImpl implements Resource {
final ResourceImpl that1 = (ResourceImpl) that;
that1.checkValid();
if (this == that1) { return true; }
-
return getCumulativeOffset(0) == that1.getCumulativeOffset(0)
&& getCapacity() == that1.getCapacity()
&& getUnsafeObject() == that1.getUnsafeObject()
@@ -349,11 +326,13 @@ public abstract class ResourceImpl implements Resource {
return true;
}
- static void checkJavaVersion(final String jdkVer, final int p0, final int p1 ) {
- final boolean ok = ((p0 == 1) && (p1 == 8)) || (p0 == 8) || (p0 == 11);
- if (!ok) { throw new IllegalArgumentException(
- "Unsupported JDK Major Version. It must be one of 1.8, 8, 11: " + jdkVer);
- }
+ final boolean isWritableType(final int typeId) { //not used
+ return (typeId & READONLY) == 0;
+ }
+
+ @Override
+ public void load() { //overridden by Map leafs
+ throw new IllegalStateException("This resource is not a memory-mapped file type.");
}
private static String pad(final String s, final int fieldLen) {
@@ -383,11 +362,17 @@ public abstract class ResourceImpl implements Resource {
//REACHABILITY FENCE
static void reachabilityFence(final Object obj) { }
+ final static int removeNnBuf(final int typeId) { return typeId & ~NONNATIVE & ~BUFFER; }
+
@Override
public void setMemoryRequestServer(final MemoryRequestServer memReqSvr) {
this.memReqSvr = memReqSvr;
}
+ final static int setReadOnlyType(final int typeId, final boolean readOnly) {
+ return readOnly ? typeId | READONLY : typeId & ~READONLY;
+ }
+
/**
* Returns a formatted hex string of an area of this object.
* Used primarily for testing.
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 e90b956..d40ce05 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
@@ -55,7 +55,7 @@ public class Buffer2Test {
assertEquals(a1, b1);
}
- assertEquals(true, buffer.hasArray());
+ assertEquals(true, buffer.isHeapResource());
assertEquals(true, buffer.isByteBufferResource());
}
@@ -75,7 +75,7 @@ public class Buffer2Test {
assertEquals(bb.get(), buffer.getByte());
}
- assertEquals(false, buffer.hasArray());
+ assertEquals(false, buffer.isHeapResource());
assertEquals(true, buffer.isByteBufferResource());
}
@@ -98,7 +98,7 @@ public class Buffer2Test {
buffer.getByteArray(copyByteArray, 0, 64);
assertEquals(byteArray, copyByteArray);
- assertEquals(true, buffer.hasArray());
+ assertEquals(true, buffer.isHeapResource());
assertEquals(false, buffer.isByteBufferResource());
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
index 8edbd46..ac90665 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
@@ -107,18 +107,4 @@ public class BufferBoundaryCheckTest {
writableMemory.putDouble(1, 1d);
}
- @Test(expectedExceptions = MemoryBoundsException.class)
- public void testGetAndAddLong() {
- writableMemory.getAndAddLong(1, 1L);
- }
-
- @Test(expectedExceptions = MemoryBoundsException.class)
- public void testGetAndSetLong() {
- writableMemory.getAndSetLong(1, 1L);
- }
-
- @Test(expectedExceptions = MemoryBoundsException.class)
- public void testCompareAndSwapLong() {
- writableMemory.compareAndSwapLong(1, 0L, 1L);
- }
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
index dbac94a..b617ccc 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/CommonMemoryTest.java
@@ -278,32 +278,6 @@ public class CommonMemoryTest {
}
}
- @Test
- public void checkAtomicMethods() throws Exception {
- int memCapacity = 8;
- try (WritableMemory mem = WritableMemory.allocateDirect(memCapacity)) {
- assertEquals(mem.getCapacity(), memCapacity);
- atomicMethodTests(mem);
- }
- }
-
- public static void atomicMethodTests(WritableMemory mem) {
- mem.putLong(0, 500);
- mem.getAndAddLong(0, 1);
- assertEquals(mem.getLong(0), 501);
-
- mem.putInt(0, 500);
- boolean b = mem.compareAndSwapLong(0, 500, 501);
- assertTrue(b);
- assertEquals(mem.getLong(0), 501);
-
- mem.putLong(0, 500);
- long oldLong = mem.getAndSetLong(0, 501);
- long newLong = mem.getLong(0);
- assertEquals(oldLong, 500);
- assertEquals(newLong, 501);
- }
-
@Test
public void checkSetClearMemoryRegions() throws Exception {
int memCapacity = 64; //must be 64
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 5dad4ec..cc76b31 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
@@ -175,7 +175,7 @@ public class LeafImplTest {
assertEquals(mem.asWritableBuffer(oo).getShort(0), 256);
assertEquals(mem.getTotalOffset(), 0);
- ByteBuffer bb = mem.getByteBuffer();
+ ByteBuffer bb = ((ResourceImpl)mem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
assertTrue(mem.getByteOrder() == bo);
@@ -204,7 +204,7 @@ public class LeafImplTest {
assertEquals(buf.writableDuplicate(oo).getShort(0), 256);
assertEquals(buf.getTotalOffset(), 0);
- bb = buf.getByteBuffer();
+ bb = ((ResourceImpl)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 = ((ResourceImpl)nnMem).getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);
assertTrue(nnMem.getByteOrder() == oo);
@@ -259,7 +259,7 @@ public class LeafImplTest {
assertEquals(nnBuf.writableDuplicate(bo).getShort(0), 1);
assertEquals(nnBuf.writableDuplicate(oo).getShort(0), 256);
- bb = nnBuf.getByteBuffer();
+ bb = ((ResourceImpl)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/MurmurHash3v2Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v2Test.java
deleted file mode 100644
index d64965c..0000000
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/MurmurHash3v2Test.java
+++ /dev/null
@@ -1,399 +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.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 (Memory mem = WritableMemory.allocateDirect(8)) {
- long[] out = new long[2];
- 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 2dc582e..7a626b0 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
@@ -69,7 +69,7 @@ public class NativeWritableBufferImplTest {
for (int i = 0; i < 8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- assertTrue(buf.hasArray());
+ assertTrue(buf.isHeapResource());
}
@Test
@@ -249,7 +249,7 @@ public class NativeWritableBufferImplTest {
}
assertTrue(wbuf.isByteBufferResource());
- ByteBuffer byteBuf2 = wbuf.getByteBuffer();
+ ByteBuffer byteBuf2 = ((ResourceImpl)wbuf).getByteBuffer();
assertEquals(byteBuf2, byteBuf);
//println( mem.toHexString("HeapBB", 0, memCapacity));
}
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 57ecd23..7f768e0 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
@@ -67,7 +67,7 @@ public class NativeWritableMemoryImplTest {
for (int i = 0; i < 8; i++) {
assertEquals(dstArray[i], srcArray[i]);
}
- assertTrue(mem.hasArray());
+ assertTrue(mem.isHeapResource());
}
@Test
@@ -428,7 +428,7 @@ public class NativeWritableMemoryImplTest {
}
assertTrue(wmem.isByteBufferResource());
- ByteBuffer byteBuf2 = wmem.getByteBuffer();
+ ByteBuffer byteBuf2 = ((ResourceImpl)wmem).getByteBuffer();
assertEquals(byteBuf2, byteBuf);
//println( mem.toHexString("HeapBB", 0, memCapacity));
}
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
index cf1076c..26f101d 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/NonNativeWritableMemoryImplTest.java
@@ -20,12 +20,10 @@
package org.apache.datasketches.memory.internal;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
import java.nio.ByteOrder;
import org.apache.datasketches.memory.Memory;
-import org.apache.datasketches.memory.MemoryBoundsException;
import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.Test;
@@ -167,41 +165,6 @@ public class NonNativeWritableMemoryImplTest {
assertEquals(arr2, arr1);
}
- //check Atomic Write Methods
-
- @Test
- public void testGetAndAddLong() {
- wmem.getAndAddLong(0, 1L);
- try {
- wmem.getAndAddLong(1, 1L);
- fail("Expected MemoryBoundsException");
- } catch (final MemoryBoundsException expected) {
- // ignore
- }
- }
-
- @Test
- public void testGetAndSetLong() {
- wmem.getAndSetLong(0, 1L);
- try {
- wmem.getAndSetLong(1, 1L);
- fail("Expected MemoryBoundsException");
- } catch (final MemoryBoundsException expected) {
- // ignore
- }
- }
-
- @Test
- public void testCompareAndSwapLong() {
- wmem.compareAndSwapLong(0, 0L, 1L);
- try {
- wmem.compareAndSwapLong(1, 0L, 1L);
- fail("Expected MemoryBoundsException");
- } catch (final MemoryBoundsException expected) {
- // ignore
- }
- }
-
//check Region
@Test
public void checkRegion() {
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
index 39f0f74..9dbccf4 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/WritableMemoryTest.java
@@ -65,9 +65,9 @@ public class WritableMemoryTest {
public void checkGetArray() {
byte[] byteArr = new byte[64];
WritableMemory wmem = WritableMemory.writableWrap(byteArr);
- assertTrue(wmem.getArray() == byteArr);
+ assertTrue(((BaseWritableMemoryImpl) wmem).getArray() == byteArr);
WritableBuffer wbuf = wmem.asWritableBuffer();
- assertTrue(wbuf.getArray() == byteArr);
+ assertTrue(((BaseWritableBufferImpl)wbuf).getArray() == byteArr);
}
@Test(expectedExceptions = IllegalArgumentException.class)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org