Skip to content

Commit df4a27c

Browse files
committed
[CODEC-268] Deprecate MurmurHash4.hash64
This is not part of the MurmurHash3 implementation. It was ported from Apache Hive. The hash collision properties are unknown for this method. Updated the javadoc to make it clear that the method does not return a hash that matches either part of the 128-bit hash function.
1 parent 9a84b3a commit df4a27c

1 file changed

Lines changed: 50 additions & 14 deletions

File tree

src/main/java/org/apache/commons/codec/digest/MurmurHash3.java

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
* </blockquote>
4040
*
4141
* <p>Original adaption from Apache Hive. That adaption contains a {@code hash64} method
42-
* that is not part of the original MurmurHash3 code.<p>
42+
* that is not part of the original MurmurHash3 code. It is not recommended to use these methods.
43+
* They will be removed in a future release. To obtain a 64-bit hash use half of the bits
44+
* from the {@code hash128x64} methods using the input data converted to bytes.<p>
4345
*
4446
* @see <a href="https://en.wikipedia.org/wiki/MurmurHash">MurmurHash</a>
4547
* @see <a href="https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp">
@@ -428,9 +430,12 @@ public static int hash32x86(final byte[] data, final int offset, final int lengt
428430
/**
429431
* Generates 64-bit hash from a long with a default seed.
430432
*
433+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
434+
*
431435
* <p>This is a Murmur3-like 64-bit variant.
432-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
433-
* It may be removed in a future release.</p>
436+
* The method does not produce the same result as either half of the hash bytes from
437+
* {@linkplain #hash128x64(byte[])} with the same byte data from the {@code long}.
438+
* This method will be removed in a future release.</p>
434439
*
435440
* <p>This is a helper method that will produce the same result as:</p>
436441
*
@@ -445,7 +450,10 @@ public static int hash32x86(final byte[] data, final int offset, final int lengt
445450
* @param data The long to hash
446451
* @return The 64-bit hash
447452
* @see #hash64(byte[], int, int, int)
453+
* @deprecated Not part of the MurmurHash3 implementation.
454+
* Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code long}.
448455
*/
456+
@Deprecated
449457
public static long hash64(final long data) {
450458
long hash = DEFAULT_SEED;
451459
long k = Long.reverseBytes(data);
@@ -465,9 +473,12 @@ public static long hash64(final long data) {
465473
/**
466474
* Generates 64-bit hash from an int with a default seed.
467475
*
476+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
477+
*
468478
* <p>This is a Murmur3-like 64-bit variant.
469-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
470-
* It may be removed in a future release.</p>
479+
* The method does not produce the same result as either half of the hash bytes from
480+
* {@linkplain #hash128x64(byte[])} with the same byte data from the {@code int}.
481+
* This method will be removed in a future release.</p>
471482
*
472483
* <p>This is a helper method that will produce the same result as:</p>
473484
*
@@ -482,7 +493,10 @@ public static long hash64(final long data) {
482493
* @param data The int to hash
483494
* @return The 64-bit hash
484495
* @see #hash64(byte[], int, int, int)
496+
* @deprecated Not part of the MurmurHash3 implementation.
497+
* Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code int}.
485498
*/
499+
@Deprecated
486500
public static long hash64(final int data) {
487501
long k1 = Integer.reverseBytes(data) & (-1L >>> 32);
488502
final int length = INTEGER_BYTES;
@@ -500,9 +514,12 @@ public static long hash64(final int data) {
500514
/**
501515
* Generates 64-bit hash from a short with a default seed.
502516
*
517+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
518+
*
503519
* <p>This is a Murmur3-like 64-bit variant.
504-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
505-
* It may be removed in a future release.</p>
520+
* The method does not produce the same result as either half of the hash bytes from
521+
* {@linkplain #hash128x64(byte[])} with the same byte data from the {@code short}.
522+
* This method will be removed in a future release.</p>
506523
*
507524
* <p>This is a helper method that will produce the same result as:</p>
508525
*
@@ -517,7 +534,10 @@ public static long hash64(final int data) {
517534
* @param data The short to hash
518535
* @return The 64-bit hash
519536
* @see #hash64(byte[], int, int, int)
537+
* @deprecated Not part of the MurmurHash3 implementation.
538+
* Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code short}.
520539
*/
540+
@Deprecated
521541
public static long hash64(final short data) {
522542
long hash = DEFAULT_SEED;
523543
long k1 = 0;
@@ -537,9 +557,12 @@ public static long hash64(final short data) {
537557
/**
538558
* Generates 64-bit hash from a byte array with a default seed.
539559
*
560+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
561+
*
540562
* <p>This is a Murmur3-like 64-bit variant.
541-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
542-
* It may be removed in a future release.</p>
563+
* The method does not produce the same result as either half of the hash bytes from
564+
* {@linkplain #hash128x64(byte[])} with the same byte data.
565+
* This method will be removed in a future release.</p>
543566
*
544567
* <p>This is a helper method that will produce the same result as:</p>
545568
*
@@ -552,17 +575,23 @@ public static long hash64(final short data) {
552575
* @param data The input byte array
553576
* @return The 64-bit hash
554577
* @see #hash64(byte[], int, int, int)
578+
* @deprecated Not part of the MurmurHash3 implementation.
579+
* Use half of the hash bytes from {@link #hash128x64(byte[])}.
555580
*/
581+
@Deprecated
556582
public static long hash64(final byte[] data) {
557583
return hash64(data, 0, data.length, DEFAULT_SEED);
558584
}
559585

560586
/**
561587
* Generates 64-bit hash from a byte array with the given offset and length and a default seed.
562588
*
589+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
590+
*
563591
* <p>This is a Murmur3-like 64-bit variant.
564-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
565-
* It may be removed in a future release.</p>
592+
* The method does not produce the same result as either half of the hash bytes from
593+
* {@linkplain #hash128x64(byte[])} with the same byte data.
594+
* This method will be removed in a future release.</p>
566595
*
567596
* <p>This is a helper method that will produce the same result as:</p>
568597
*
@@ -576,17 +605,21 @@ public static long hash64(final byte[] data) {
576605
* @param length The length of array
577606
* @return The 64-bit hash
578607
* @see #hash64(byte[], int, int, int)
608+
* @deprecated Not part of the MurmurHash3 implementation.
609+
* Use half of the hash bytes from {@link #hash128x64(byte[], int, int, int)}.
579610
*/
611+
@Deprecated
580612
public static long hash64(final byte[] data, final int offset, final int length) {
581613
return hash64(data, offset, length, DEFAULT_SEED);
582614
}
583615

584616
/**
585617
* Generates 64-bit hash from a byte array with the given offset, length and seed.
586618
*
619+
* <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
620+
*
587621
* <p>This is a Murmur3-like 64-bit variant.
588-
* <strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong>
589-
* It may be removed in a future release.</p>
622+
* This method will be removed in a future release.</p>
590623
*
591624
* <p>This algorithm processes 8 bytes chunks of data in a manner similar to the 16 byte chunks
592625
* of data processed in the MurmurHash3 {@code MurmurHash3_x64_128} method. However the hash
@@ -602,7 +635,10 @@ public static long hash64(final byte[] data, final int offset, final int length)
602635
* @param length The length of array
603636
* @param seed The initial seed value
604637
* @return The 64-bit hash
638+
* @deprecated Not part of the MurmurHash3 implementation.
639+
* Use half of the hash bytes from {@link #hash128x64(byte[], int, int, int)}.
605640
*/
641+
@Deprecated
606642
public static long hash64(final byte[] data, final int offset, final int length, final int seed) {
607643
// ************
608644
// Note: This fails to apply masking using 0xffffffffL to the seed.
@@ -961,7 +997,7 @@ public static class IncrementalHash32x86 {
961997
/** The total number of input bytes added since the start. */
962998
private int totalLen;
963999
/**
964-
* The current running hash.
1000+
* The current running hash.
9651001
* This must be finalised to generate the 32-bit hash value.
9661002
*/
9671003
private int hash;

0 commit comments

Comments
 (0)