You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2021/07/18 20:55:29 UTC
[datasketches-java] branch Memory2 updated: Updates to
MurmurHash3v2.
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch Memory2
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
The following commit(s) were added to refs/heads/Memory2 by this push:
new 7d3ee1b Updates to MurmurHash3v2.
7d3ee1b is described below
commit 7d3ee1b5fbd8cdb59f56f2d42ef9fec1f58635bc
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sun Jul 18 13:55:15 2021 -0700
Updates to MurmurHash3v2.
---
.../apache/datasketches/hash/MurmurHash3v2.java | 33 ++++++++++++----------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/hash/MurmurHash3v2.java b/src/main/java/org/apache/datasketches/hash/MurmurHash3v2.java
index d2500df..3e77bc6 100644
--- a/src/main/java/org/apache/datasketches/hash/MurmurHash3v2.java
+++ b/src/main/java/org/apache/datasketches/hash/MurmurHash3v2.java
@@ -52,14 +52,14 @@ public final class MurmurHash3v2 {
/**
* Returns a 128-bit hash of the input.
* Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now returns a hash.
+ * 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)) {
- emptyOrNull();
+ throw new IllegalArgumentException("Input in is empty or null.");
}
return hash(Memory.wrap(in), 0L, in.length << 3, seed, new long[2]);
}
@@ -67,14 +67,14 @@ public final class MurmurHash3v2 {
/**
* Returns a 128-bit hash of the input.
* Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now returns a hash.
+ * 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)) {
- emptyOrNull();
+ throw new IllegalArgumentException("Input in is empty or null.");
}
return hash(Memory.wrap(in), 0L, in.length << 2, seed, new long[2]);
}
@@ -82,14 +82,14 @@ public final class MurmurHash3v2 {
/**
* Returns a 128-bit hash of the input.
* Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now returns a hash.
+ * 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)) {
- emptyOrNull();
+ throw new IllegalArgumentException("Input in is empty or null.");
}
return hash(Memory.wrap(in), 0L, in.length << 1, seed, new long[2]);
}
@@ -97,14 +97,14 @@ public final class MurmurHash3v2 {
/**
* Returns a 128-bit hash of the input.
* Provided for compatibility with older version of MurmurHash3,
- * but empty or null input now returns a hash.
+ * 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)) {
- emptyOrNull();
+ throw new IllegalArgumentException("Input in is empty or null.");
}
return hash(Memory.wrap(in), 0L, in.length, seed, new long[2]);
}
@@ -143,6 +143,7 @@ public final class MurmurHash3v2 {
/**
* 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
@@ -150,7 +151,7 @@ public final class MurmurHash3v2 {
*/
public static long[] hash(final String in, final long seed, final long[] hashOut) {
if ((in == null) || (in.length() == 0)) {
- emptyOrNull();
+ 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);
@@ -161,7 +162,8 @@ public final class MurmurHash3v2 {
/**
* 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.
+ * @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.
@@ -171,9 +173,13 @@ public final class MurmurHash3v2 {
@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)) { emptyOrNull(); }
+ if ((mem == null) || (mem.getCapacity() == 0L)) {
+ throw new IllegalArgumentException("Input mem is empty or null.");
+ }
final Object uObj = ((WritableMemory) mem).getArray();
- if (uObj == null) { emptyOrNull(); }
+ if (uObj == null) {
+ throw new IllegalArgumentException("The backing resource of input mem is not on-heap.");
+ }
long cumOff = mem.getCumulativeOffset() + offsetBytes;
long h1 = seed;
@@ -354,7 +360,4 @@ public final class MurmurHash3v2 {
return hashOut;
}
- private static void emptyOrNull() {
- throw new IllegalArgumentException("Input is empty, null or mem is not on-heap.");
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org