MurmurHash3.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.codec.digest;

  18. import org.apache.commons.codec.binary.StringUtils;

  19. /**
  20.  * Implements the MurmurHash3 32-bit and 128-bit hash functions.
  21.  *
  22.  * <p>
  23.  * MurmurHash is a non-cryptographic hash function suitable for general hash-based lookup. The name comes from two basic
  24.  * operations, multiply (MU) and rotate (R), used in its inner loop. Unlike cryptographic hash functions, it is not
  25.  * specifically designed to be difficult to reverse by an adversary, making it unsuitable for cryptographic purposes.
  26.  * </p>
  27.  *
  28.  * <p>
  29.  * This contains a Java port of the 32-bit hash function {@code MurmurHash3_x86_32} and the 128-bit hash function
  30.  * {@code MurmurHash3_x64_128} from Austin Appleby's original {@code c++} code in SMHasher.
  31.  * </p>
  32.  *
  33.  * <p>
  34.  * This is public domain code with no copyrights. From home page of
  35.  * <a href="https://github.com/aappleby/smhasher">SMHasher</a>:
  36.  * </p>
  37.  *
  38.  * <blockquote>
  39.  * "All MurmurHash versions are public domain software, and the author disclaims all copyright to their
  40.  * code."
  41.  * </blockquote>
  42.  *
  43.  * <p>
  44.  * Original adaption from <a href="https://hive.apache.org/">Apache Hive</a>.
  45.  * That adaption contains a {@code hash64} method that is not part of the original
  46.  * MurmurHash3 code. It is not recommended to use these methods. They will be removed in a future release. To obtain a
  47.  * 64-bit hash use half of the bits from the {@code hash128x64} methods using the input data converted to bytes.
  48.  * </p>
  49.  *
  50.  * @see <a href="https://en.wikipedia.org/wiki/MurmurHash">MurmurHash</a>
  51.  * @see <a href="https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp"> Original MurmurHash3 C++
  52.  *      code</a>
  53.  * @see <a href=
  54.  *      "https://github.com/apache/hive/blob/master/storage-api/src/java/org/apache/hive/common/util/Murmur3.java">
  55.  *      Apache Hive Murmer3</a>
  56.  * @since 1.13
  57.  */
  58. public final class MurmurHash3 {

  59.     /**
  60.      * Generates 32-bit hash from input bytes. Bytes can be added incrementally and the new
  61.      * hash computed.
  62.      *
  63.      * <p>
  64.      * This is an implementation of the 32-bit hash function {@code MurmurHash3_x86_32}
  65.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  66.      * </p>
  67.      *
  68.      * <p>
  69.      * This implementation contains a sign-extension bug in the finalization step of
  70.      * any bytes left over from dividing the length by 4. This manifests if any of these
  71.      * bytes are negative.
  72.      * </p>
  73.      *
  74.      * @deprecated Use IncrementalHash32x86. This corrects the processing of trailing bytes.
  75.      */
  76.     @Deprecated
  77.     public static class IncrementalHash32 extends IncrementalHash32x86 {

  78.         /**
  79.          * Constructs a new instance.
  80.          */
  81.         public IncrementalHash32() {
  82.             // empty
  83.         }

  84.         /**
  85.          * {@inheritDoc}
  86.          *
  87.          * <p>
  88.          * This implementation contains a sign-extension bug in the finalization step of
  89.          * any bytes left over from dividing the length by 4. This manifests if any of these
  90.          * bytes are negative.
  91.          * <p>
  92.          *
  93.          * @deprecated Use IncrementalHash32x86. This corrects the processing of trailing bytes.
  94.          */
  95.         @Override
  96.         @Deprecated
  97.         int finalise(final int hash, final int unprocessedLength, final byte[] unprocessed, final int totalLen) {
  98.             int result = hash;
  99.             // Note: This fails to apply masking using 0xff to the 3 remaining bytes.
  100.             int k1 = 0;
  101.             switch (unprocessedLength) {
  102.             case 3:
  103.                 k1 ^= unprocessed[2] << 16;
  104.                 // falls-through
  105.             case 2:
  106.                 k1 ^= unprocessed[1] << 8;
  107.                 // falls-through
  108.             case 1:
  109.                 k1 ^= unprocessed[0];
  110.                 // mix functions
  111.                 k1 *= C1_32;
  112.                 k1 = Integer.rotateLeft(k1, R1_32);
  113.                 k1 *= C2_32;
  114.                 result ^= k1;
  115.             }
  116.             // finalization
  117.             result ^= totalLen;
  118.             return fmix32(result);
  119.         }
  120.     }

  121.     /**
  122.      * Generates 32-bit hash from input bytes. Bytes can be added incrementally and the new
  123.      * hash computed.
  124.      *
  125.      * <p>
  126.      * This is an implementation of the 32-bit hash function {@code MurmurHash3_x86_32}
  127.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  128.      * </p>
  129.      *
  130.      * @since 1.14
  131.      */
  132.     public static class IncrementalHash32x86 {

  133.         /** The size of byte blocks that are processed together. */
  134.         private static final int BLOCK_SIZE = 4;

  135.         /**
  136.          * Combines the bytes using an Or operation ({@code | } in a little-endian representation
  137.          * of a 32-bit integer; byte 1 will be the least significant byte, byte 4 the most
  138.          * significant.
  139.          *
  140.          * @param b1 The first byte
  141.          * @param b2 The second byte
  142.          * @param b3 The third byte
  143.          * @param b4 The fourth byte
  144.          * @return The 32-bit integer
  145.          */
  146.         private static int orBytes(final byte b1, final byte b2, final byte b3, final byte b4) {
  147.             return b1 & 0xff | (b2 & 0xff) << 8 | (b3 & 0xff) << 16 | (b4 & 0xff) << 24;
  148.         }

  149.         /** Up to 3 unprocessed bytes from input data. */
  150.         private final byte[] unprocessed = new byte[3];

  151.         /** The number of unprocessed bytes in the tail data. */
  152.         private int unprocessedLength;

  153.         /** The total number of input bytes added since the start. */
  154.         private int totalLen;

  155.         /**
  156.          * The current running hash.
  157.          * This must be finalized to generate the 32-bit hash value.
  158.          */
  159.         private int hash;

  160.         /**
  161.          * Constructs a new instance.
  162.          */
  163.         public IncrementalHash32x86() {
  164.             // empty
  165.         }

  166.         /**
  167.          * Adds the byte array to the current incremental hash.
  168.          *
  169.          * @param data The input byte array
  170.          * @param offset The offset of data
  171.          * @param length The length of array
  172.          */
  173.         public final void add(final byte[] data, final int offset, final int length) {
  174.             if (length <= 0) {
  175.                 // Nothing to add
  176.                 return;
  177.             }
  178.             totalLen += length;
  179.             // Process the bytes in blocks of 4.
  180.             // New bytes must be added to any current unprocessed bytes,
  181.             // then processed in blocks of 4 and the remaining bytes saved:
  182.             //
  183.             //    |--|---------------------------|--|
  184.             // unprocessed
  185.             //                main block
  186.             //                                remaining

  187.             // Check if the unprocessed bytes and new bytes can fill a block of 4.
  188.             // Make this overflow safe in the event that length is Integer.MAX_VALUE.
  189.             // Equivalent to: (unprocessedLength + length < BLOCK_SIZE)
  190.             if (unprocessedLength + length - BLOCK_SIZE < 0) {
  191.                 // Not enough so add to the unprocessed bytes
  192.                 System.arraycopy(data, offset, unprocessed, unprocessedLength, length);
  193.                 unprocessedLength += length;
  194.                 return;
  195.             }
  196.             // Combine unprocessed bytes with new bytes.
  197.             final int newOffset;
  198.             final int newLength;
  199.             if (unprocessedLength > 0) {
  200.                 int k = -1;
  201.                 switch (unprocessedLength) {
  202.                 case 1:
  203.                     k = orBytes(unprocessed[0], data[offset], data[offset + 1], data[offset + 2]);
  204.                     break;
  205.                 case 2:
  206.                     k = orBytes(unprocessed[0], unprocessed[1], data[offset], data[offset + 1]);
  207.                     break;
  208.                 case 3:
  209.                     k = orBytes(unprocessed[0], unprocessed[1], unprocessed[2], data[offset]);
  210.                     break;
  211.                 default:
  212.                     throw new IllegalStateException("Unprocessed length should be 1, 2, or 3: " + unprocessedLength);
  213.                 }
  214.                 hash = mix32(k, hash);
  215.                 // Update the offset and length
  216.                 final int consumed = BLOCK_SIZE - unprocessedLength;
  217.                 newOffset = offset + consumed;
  218.                 newLength = length - consumed;
  219.             } else {
  220.                 newOffset = offset;
  221.                 newLength = length;
  222.             }
  223.             // Main processing of blocks of 4 bytes
  224.             final int nblocks = newLength >> 2;

  225.             for (int i = 0; i < nblocks; i++) {
  226.                 final int index = newOffset + (i << 2);
  227.                 final int k = MurmurHash.getLittleEndianInt(data, index);
  228.                 hash = mix32(k, hash);
  229.             }
  230.             // Save left-over unprocessed bytes
  231.             final int consumed = nblocks << 2;
  232.             unprocessedLength = newLength - consumed;
  233.             if (unprocessedLength != 0) {
  234.                 System.arraycopy(data, newOffset + consumed, unprocessed, 0, unprocessedLength);
  235.             }
  236.         }

  237.         /**
  238.          * Generates the 32-bit hash value. Repeat calls to this method with no additional data
  239.          * will generate the same hash value.
  240.          *
  241.          * @return The 32-bit hash
  242.          */
  243.         public final int end() {
  244.             // Allow calling end() again after adding no data to return the same result.
  245.             return finalise(hash, unprocessedLength, unprocessed, totalLen);
  246.         }

  247.         /**
  248.          * Finalizes the running hash to the output 32-bit hash by processing remaining bytes
  249.          * and performing final mixing.
  250.          *
  251.          * @param hash The running hash
  252.          * @param unprocessedLength The number of unprocessed bytes in the tail data.
  253.          * @param unprocessed Up to 3 unprocessed bytes from input data.
  254.          * @param totalLen The total number of input bytes added since the start.
  255.          * @return The 32-bit hash
  256.          */
  257.         int finalise(final int hash, final int unprocessedLength, final byte[] unprocessed, final int totalLen) {
  258.             int result = hash;
  259.             int k1 = 0;
  260.             switch (unprocessedLength) {
  261.             case 3:
  262.                 k1 ^= (unprocessed[2] & 0xff) << 16;
  263.                 // falls-through
  264.             case 2:
  265.                 k1 ^= (unprocessed[1] & 0xff) << 8;
  266.                 // falls-through
  267.             case 1:
  268.                 k1 ^= unprocessed[0] & 0xff;
  269.                 // mix functions
  270.                 k1 *= C1_32;
  271.                 k1 = Integer.rotateLeft(k1, R1_32);
  272.                 k1 *= C2_32;
  273.                 result ^= k1;
  274.             }
  275.             // finalization
  276.             result ^= totalLen;
  277.             return fmix32(result);
  278.         }

  279.         /**
  280.          * Starts a new incremental hash.
  281.          *
  282.          * @param seed The initial seed value
  283.          */
  284.         public final void start(final int seed) {
  285.             // Reset
  286.             unprocessedLength = totalLen = 0;
  287.             hash = seed;
  288.         }
  289.     }

  290.     /**
  291.      * A random number to use for a hash code.
  292.      *
  293.      * @deprecated This is not used internally and will be removed in a future release.
  294.      */
  295.     @Deprecated
  296.     public static final long NULL_HASHCODE = 2862933555777941757L;
  297.     /**
  298.      * A default seed to use for the murmur hash algorithm.
  299.      * Has the value {@code 104729}.
  300.      */
  301.     public static final int DEFAULT_SEED = 104729;
  302.     // Constants for 32-bit variant
  303.     private static final int C1_32 = 0xcc9e2d51;
  304.     private static final int C2_32 = 0x1b873593;
  305.     private static final int R1_32 = 15;
  306.     private static final int R2_32 = 13;

  307.     private static final int M_32 = 5;
  308.     private static final int N_32 = 0xe6546b64;
  309.     // Constants for 128-bit variant
  310.     private static final long C1 = 0x87c37b91114253d5L;
  311.     private static final long C2 = 0x4cf5ad432745937fL;
  312.     private static final int R1 = 31;
  313.     private static final int R2 = 27;
  314.     private static final int R3 = 33;
  315.     private static final int M = 5;

  316.     private static final int N1 = 0x52dce729;

  317.     private static final int N2 = 0x38495ab5;

  318.     /**
  319.      * Performs the final avalanche mix step of the 32-bit hash function {@code MurmurHash3_x86_32}.
  320.      *
  321.      * @param hash The current hash
  322.      * @return The final hash
  323.      */
  324.     private static int fmix32(int hash) {
  325.         hash ^= hash >>> 16;
  326.         hash *= 0x85ebca6b;
  327.         hash ^= hash >>> 13;
  328.         hash *= 0xc2b2ae35;
  329.         hash ^= hash >>> 16;
  330.         return hash;
  331.     }

  332.     /**
  333.      * Performs the final avalanche mix step of the 64-bit hash function {@code MurmurHash3_x64_128}.
  334.      *
  335.      * @param hash The current hash
  336.      * @return The final hash
  337.      */
  338.     private static long fmix64(long hash) {
  339.         hash ^= hash >>> 33;
  340.         hash *= 0xff51afd7ed558ccdL;
  341.         hash ^= hash >>> 33;
  342.         hash *= 0xc4ceb9fe1a85ec53L;
  343.         hash ^= hash >>> 33;
  344.         return hash;
  345.     }

  346.     /**
  347.      * Generates 128-bit hash from the byte array with a default seed.
  348.      * This is a helper method that will produce the same result as:
  349.      *
  350.      * <pre>
  351.      * int offset = 0;
  352.      * int seed = 104729;
  353.      * int hash = MurmurHash3.hash128(data, offset, data.length, seed);
  354.      * </pre>
  355.      *
  356.      * <p>
  357.      * Note: The sign extension bug in {@link #hash128(byte[], int, int, int)} does not effect
  358.      * this result as the default seed is positive.
  359.      * </p>
  360.      *
  361.      * @param data The input byte array
  362.      * @return The 128-bit hash (2 longs)
  363.      * @see #hash128(byte[], int, int, int)
  364.      */
  365.     public static long[] hash128(final byte[] data) {
  366.         return hash128(data, 0, data.length, DEFAULT_SEED);
  367.     }

  368.     /**
  369.      * Generates 128-bit hash from the byte array with the given offset, length and seed.
  370.      *
  371.      * <p>
  372.      * This is an implementation of the 128-bit hash function {@code MurmurHash3_x64_128}
  373.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  374.      * </p>
  375.      *
  376.      * <p>
  377.      * This implementation contains a sign-extension bug in the seed initialization.
  378.      * This manifests if the seed is negative.
  379.      * </p>
  380.      *
  381.      * @param data The input byte array
  382.      * @param offset The first element of array
  383.      * @param length The length of array
  384.      * @param seed The initial seed value
  385.      * @return The 128-bit hash (2 longs)
  386.      * @deprecated Use {@link #hash128x64(byte[], int, int, int)}. This corrects the seed initialization.
  387.      */
  388.     @Deprecated
  389.     public static long[] hash128(final byte[] data, final int offset, final int length, final int seed) {
  390.         // Note: This deliberately fails to apply masking using 0xffffffffL to the seed
  391.         // to maintain behavioral compatibility with the original version.
  392.         // The implicit conversion to a long will extend a negative sign
  393.         // bit through the upper 32-bits of the long seed. These should be zero.
  394.         return hash128x64Internal(data, offset, length, seed);
  395.     }

  396.     /**
  397.      * Generates 128-bit hash from a string with a default seed.
  398.      * <p>
  399.      * Before 1.14 the string was converted using default encoding.
  400.      * Since 1.14 the string is converted to bytes using UTF-8 encoding.
  401.      * </p>
  402.      * <p>
  403.      * This is a helper method that will produce the same result as:
  404.      * </p>
  405.      *
  406.      * <pre>
  407.      * int offset = 0;
  408.      * int seed = 104729;
  409.      * byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
  410.      * int hash = MurmurHash3.hash128(bytes, offset, bytes.length, seed);
  411.      * </pre>
  412.      *
  413.      * <p>
  414.      * Note: The sign extension bug in {@link #hash128(byte[], int, int, int)} does not effect
  415.      * this result as the default seed is positive.
  416.      * </p>
  417.      *
  418.      * @param data The input String
  419.      * @return The 128-bit hash (2 longs)
  420.      * @see #hash128(byte[], int, int, int)
  421.      * @deprecated Use {@link #hash128x64(byte[])} using the bytes returned from
  422.      * {@link String#getBytes(java.nio.charset.Charset)}.
  423.      */
  424.     @Deprecated
  425.     public static long[] hash128(final String data) {
  426.         final byte[] bytes = StringUtils.getBytesUtf8(data);
  427.         return hash128(bytes, 0, bytes.length, DEFAULT_SEED);
  428.     }

  429.     /**
  430.      * Generates 128-bit hash from the byte array with a seed of zero.
  431.      * This is a helper method that will produce the same result as:
  432.      *
  433.      * <pre>
  434.      * int offset = 0;
  435.      * int seed = 0;
  436.      * int hash = MurmurHash3.hash128x64(data, offset, data.length, seed);
  437.      * </pre>
  438.      *
  439.      * @param data The input byte array
  440.      * @return The 128-bit hash (2 longs)
  441.      * @see #hash128x64(byte[], int, int, int)
  442.      * @since 1.14
  443.      */
  444.     public static long[] hash128x64(final byte[] data) {
  445.         return hash128x64(data, 0, data.length, 0);
  446.     }

  447.     /**
  448.      * Generates 128-bit hash from the byte array with the given offset, length and seed.
  449.      *
  450.      * <p>
  451.      * This is an implementation of the 128-bit hash function {@code MurmurHash3_x64_128}
  452.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  453.      * </p>
  454.      *
  455.      * @param data The input byte array
  456.      * @param offset The first element of array
  457.      * @param length The length of array
  458.      * @param seed The initial seed value
  459.      * @return The 128-bit hash (2 longs)
  460.      * @since 1.14
  461.      */
  462.     public static long[] hash128x64(final byte[] data, final int offset, final int length, final int seed) {
  463.         // Use an unsigned 32-bit integer as the seed
  464.         return hash128x64Internal(data, offset, length, seed & 0xffffffffL);
  465.     }

  466.     /**
  467.      * Generates 128-bit hash from the byte array with the given offset, length and seed.
  468.      *
  469.      * <p>
  470.      * This is an implementation of the 128-bit hash function {@code MurmurHash3_x64_128}
  471.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  472.      * </p>
  473.      *
  474.      * @param data The input byte array
  475.      * @param offset The first element of array
  476.      * @param length The length of array
  477.      * @param seed The initial seed value
  478.      * @return The 128-bit hash (2 longs)
  479.      */
  480.     private static long[] hash128x64Internal(final byte[] data, final int offset, final int length, final long seed) {
  481.         long h1 = seed;
  482.         long h2 = seed;
  483.         final int nblocks = length >> 4;
  484.         // body
  485.         for (int i = 0; i < nblocks; i++) {
  486.             final int index = offset + (i << 4);
  487.             long k1 = MurmurHash.getLittleEndianLong(data, index);
  488.             long k2 = MurmurHash.getLittleEndianLong(data, index + 8);

  489.             // mix functions for k1
  490.             k1 *= C1;
  491.             k1 = Long.rotateLeft(k1, R1);
  492.             k1 *= C2;
  493.             h1 ^= k1;
  494.             h1 = Long.rotateLeft(h1, R2);
  495.             h1 += h2;
  496.             h1 = h1 * M + N1;

  497.             // mix functions for k2
  498.             k2 *= C2;
  499.             k2 = Long.rotateLeft(k2, R3);
  500.             k2 *= C1;
  501.             h2 ^= k2;
  502.             h2 = Long.rotateLeft(h2, R1);
  503.             h2 += h1;
  504.             h2 = h2 * M + N2;
  505.         }
  506.         // tail
  507.         long k1 = 0;
  508.         long k2 = 0;
  509.         final int index = offset + (nblocks << 4);
  510.         switch (offset + length - index) {
  511.         case 15:
  512.             k2 ^= ((long) data[index + 14] & 0xff) << 48;
  513.             // falls-through
  514.         case 14:
  515.             k2 ^= ((long) data[index + 13] & 0xff) << 40;
  516.             // falls-through
  517.         case 13:
  518.             k2 ^= ((long) data[index + 12] & 0xff) << 32;
  519.             // falls-through
  520.         case 12:
  521.             k2 ^= ((long) data[index + 11] & 0xff) << 24;
  522.             // falls-through
  523.         case 11:
  524.             k2 ^= ((long) data[index + 10] & 0xff) << 16;
  525.             // falls-through
  526.         case 10:
  527.             k2 ^= ((long) data[index + 9] & 0xff) << 8;
  528.             // falls-through
  529.         case 9:
  530.             k2 ^= data[index + 8] & 0xff;
  531.             k2 *= C2;
  532.             k2 = Long.rotateLeft(k2, R3);
  533.             k2 *= C1;
  534.             h2 ^= k2;
  535.             // falls-through
  536.         case 8:
  537.             k1 ^= ((long) data[index + 7] & 0xff) << 56;
  538.             // falls-through
  539.         case 7:
  540.             k1 ^= ((long) data[index + 6] & 0xff) << 48;
  541.             // falls-through
  542.         case 6:
  543.             k1 ^= ((long) data[index + 5] & 0xff) << 40;
  544.             // falls-through
  545.         case 5:
  546.             k1 ^= ((long) data[index + 4] & 0xff) << 32;
  547.             // falls-through
  548.         case 4:
  549.             k1 ^= ((long) data[index + 3] & 0xff) << 24;
  550.             // falls-through
  551.         case 3:
  552.             k1 ^= ((long) data[index + 2] & 0xff) << 16;
  553.             // falls-through
  554.         case 2:
  555.             k1 ^= ((long) data[index + 1] & 0xff) << 8;
  556.             // falls-through
  557.         case 1:
  558.             k1 ^= data[index] & 0xff;
  559.             k1 *= C1;
  560.             k1 = Long.rotateLeft(k1, R1);
  561.             k1 *= C2;
  562.             h1 ^= k1;
  563.         }
  564.         // finalization
  565.         h1 ^= length;
  566.         h2 ^= length;

  567.         h1 += h2;
  568.         h2 += h1;

  569.         h1 = fmix64(h1);
  570.         h2 = fmix64(h2);

  571.         h1 += h2;
  572.         h2 += h1;
  573.         return new long[] { h1, h2 };
  574.     }

  575.     /**
  576.      * Generates 32-bit hash from the byte array with a default seed.
  577.      * This is a helper method that will produce the same result as:
  578.      *
  579.      * <pre>
  580.      * int offset = 0;
  581.      * int seed = 104729;
  582.      * int hash = MurmurHash3.hash32(data, offset, data.length, seed);
  583.      * </pre>
  584.      *
  585.      * <p>
  586.      * This implementation contains a sign-extension bug in the finalization step of
  587.      * any bytes left over from dividing the length by 4. This manifests if any of these
  588.      * bytes are negative.
  589.      * </p>
  590.      *
  591.      * @param data The input byte array
  592.      * @return The 32-bit hash
  593.      * @see #hash32(byte[], int, int, int)
  594.      * @deprecated Use {@link #hash32x86(byte[], int, int, int)}. This corrects the processing of trailing bytes.
  595.      */
  596.     @Deprecated
  597.     public static int hash32(final byte[] data) {
  598.         return hash32(data, 0, data.length, DEFAULT_SEED);
  599.     }

  600.     /**
  601.      * Generates 32-bit hash from the byte array with the given length and a default seed.
  602.      * This is a helper method that will produce the same result as:
  603.      *
  604.      * <pre>
  605.      * int offset = 0;
  606.      * int seed = 104729;
  607.      * int hash = MurmurHash3.hash32(data, offset, length, seed);
  608.      * </pre>
  609.      *
  610.      * <p>
  611.      * This implementation contains a sign-extension bug in the finalization step of
  612.      * any bytes left over from dividing the length by 4. This manifests if any of these
  613.      * bytes are negative.
  614.      * </p>
  615.      *
  616.      * @param data The input byte array
  617.      * @param length The length of array
  618.      * @return The 32-bit hash
  619.      * @see #hash32(byte[], int, int, int)
  620.      * @deprecated Use {@link #hash32x86(byte[], int, int, int)}. This corrects the processing of trailing bytes.
  621.      */
  622.     @Deprecated
  623.     public static int hash32(final byte[] data, final int length) {
  624.         return hash32(data, length, DEFAULT_SEED);
  625.     }

  626.     /**
  627.      * Generates 32-bit hash from the byte array with the given length and seed. This is a
  628.      * helper method that will produce the same result as:
  629.      *
  630.      * <pre>
  631.      * int offset = 0;
  632.      * int hash = MurmurHash3.hash32(data, offset, length, seed);
  633.      * </pre>
  634.      *
  635.      * <p>
  636.      * This implementation contains a sign-extension bug in the finalization step of
  637.      * any bytes left over from dividing the length by 4. This manifests if any of these
  638.      * bytes are negative.
  639.      * </p>
  640.      *
  641.      * @param data The input byte array
  642.      * @param length The length of array
  643.      * @param seed The initial seed value
  644.      * @return The 32-bit hash
  645.      * @see #hash32(byte[], int, int, int)
  646.      * @deprecated Use {@link #hash32x86(byte[], int, int, int)}. This corrects the processing of trailing bytes.
  647.      */
  648.     @Deprecated
  649.     public static int hash32(final byte[] data, final int length, final int seed) {
  650.         return hash32(data, 0, length, seed);
  651.     }

  652.     /**
  653.      * Generates 32-bit hash from the byte array with the given offset, length and seed.
  654.      *
  655.      * <p>
  656.      * This is an implementation of the 32-bit hash function {@code MurmurHash3_x86_32}
  657.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  658.      * </p>
  659.      *
  660.      * <p>
  661.      * This implementation contains a sign-extension bug in the finalization step of
  662.      * any bytes left over from dividing the length by 4. This manifests if any of these
  663.      * bytes are negative.
  664.      * </p>
  665.      *
  666.      * @param data The input byte array
  667.      * @param offset The offset of data
  668.      * @param length The length of array
  669.      * @param seed The initial seed value
  670.      * @return The 32-bit hash
  671.      * @deprecated Use {@link #hash32x86(byte[], int, int, int)}. This corrects the processing of trailing bytes.
  672.      */
  673.     @Deprecated
  674.     public static int hash32(final byte[] data, final int offset, final int length, final int seed) {
  675.         int hash = seed;
  676.         final int nblocks = length >> 2;
  677.         // body
  678.         for (int i = 0; i < nblocks; i++) {
  679.             final int index = offset + (i << 2);
  680.             final int k = MurmurHash.getLittleEndianInt(data, index);
  681.             hash = mix32(k, hash);
  682.         }
  683.         // tail
  684.         // Note: This fails to apply masking using 0xff to the 3 remaining bytes.
  685.         final int index = offset + (nblocks << 2);
  686.         int k1 = 0;
  687.         switch (offset + length - index) {
  688.         case 3:
  689.             k1 ^= data[index + 2] << 16;
  690.             // falls-through
  691.         case 2:
  692.             k1 ^= data[index + 1] << 8;
  693.             // falls-through
  694.         case 1:
  695.             k1 ^= data[index];
  696.             // mix functions
  697.             k1 *= C1_32;
  698.             k1 = Integer.rotateLeft(k1, R1_32);
  699.             k1 *= C2_32;
  700.             hash ^= k1;
  701.         }
  702.         hash ^= length;
  703.         return fmix32(hash);
  704.     }

  705.     /**
  706.      * Generates 32-bit hash from a long with a default seed value.
  707.      * This is a helper method that will produce the same result as:
  708.      *
  709.      * <pre>
  710.      * int offset = 0;
  711.      * int seed = 104729;
  712.      * int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(8)
  713.      *                                            .putLong(data)
  714.      *                                            .array(), offset, 8, seed);
  715.      * </pre>
  716.      *
  717.      * @param data The long to hash
  718.      * @return The 32-bit hash
  719.      * @see #hash32x86(byte[], int, int, int)
  720.      */
  721.     public static int hash32(final long data) {
  722.         return hash32(data, DEFAULT_SEED);
  723.     }

  724.     /**
  725.      * Generates 32-bit hash from a long with the given seed.
  726.      * This is a helper method that will produce the same result as:
  727.      *
  728.      * <pre>
  729.      * int offset = 0;
  730.      * int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(8)
  731.      *                                            .putLong(data)
  732.      *                                            .array(), offset, 8, seed);
  733.      * </pre>
  734.      *
  735.      * @param data The long to hash
  736.      * @param seed The initial seed value
  737.      * @return The 32-bit hash
  738.      * @see #hash32x86(byte[], int, int, int)
  739.      */
  740.     public static int hash32(final long data, final int seed) {
  741.         int hash = seed;
  742.         final long r0 = Long.reverseBytes(data);

  743.         hash = mix32((int) r0, hash);
  744.         hash = mix32((int) (r0 >>> 32), hash);

  745.         hash ^= Long.BYTES;
  746.         return fmix32(hash);
  747.     }

  748.     /**
  749.      * Generates 32-bit hash from two longs with a default seed value.
  750.      * This is a helper method that will produce the same result as:
  751.      *
  752.      * <pre>
  753.      * int offset = 0;
  754.      * int seed = 104729;
  755.      * int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(16)
  756.      *                                            .putLong(data1)
  757.      *                                            .putLong(data2)
  758.      *                                            .array(), offset, 16, seed);
  759.      * </pre>
  760.      *
  761.      * @param data1 The first long to hash
  762.      * @param data2 The second long to hash
  763.      * @return The 32-bit hash
  764.      * @see #hash32x86(byte[], int, int, int)
  765.      */
  766.     public static int hash32(final long data1, final long data2) {
  767.         return hash32(data1, data2, DEFAULT_SEED);
  768.     }

  769.     /**
  770.      * Generates 32-bit hash from two longs with the given seed.
  771.      * This is a helper method that will produce the same result as:
  772.      *
  773.      * <pre>
  774.      * int offset = 0;
  775.      * int hash = MurmurHash3.hash32x86(ByteBuffer.allocate(16)
  776.      *                                            .putLong(data1)
  777.      *                                            .putLong(data2)
  778.      *                                            .array(), offset, 16, seed);
  779.      * </pre>
  780.      *
  781.      * @param data1 The first long to hash
  782.      * @param data2 The second long to hash
  783.      * @param seed The initial seed value
  784.      * @return The 32-bit hash
  785.      * @see #hash32x86(byte[], int, int, int)
  786.      */
  787.     public static int hash32(final long data1, final long data2, final int seed) {
  788.         int hash = seed;
  789.         final long r0 = Long.reverseBytes(data1);
  790.         final long r1 = Long.reverseBytes(data2);

  791.         hash = mix32((int) r0, hash);
  792.         hash = mix32((int) (r0 >>> 32), hash);
  793.         hash = mix32((int) r1, hash);
  794.         hash = mix32((int) (r1 >>> 32), hash);

  795.         hash ^= Long.BYTES * 2;
  796.         return fmix32(hash);
  797.     }

  798.     /**
  799.      * Generates 32-bit hash from a string with a default seed.
  800.      * <p>
  801.      * Before 1.14 the string was converted using default encoding.
  802.      * Since 1.14 the string is converted to bytes using UTF-8 encoding.
  803.      * </p>
  804.      * This is a helper method that will produce the same result as:
  805.      *
  806.      * <pre>
  807.      * int offset = 0;
  808.      * int seed = 104729;
  809.      * byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
  810.      * int hash = MurmurHash3.hash32(bytes, offset, bytes.length, seed);
  811.      * </pre>
  812.      *
  813.      * <p>
  814.      * This implementation contains a sign-extension bug in the finalization step of
  815.      * any bytes left over from dividing the length by 4. This manifests if any of these
  816.      * bytes are negative.
  817.      * </p>
  818.      *
  819.      * @param data The input string
  820.      * @return The 32-bit hash
  821.      * @see #hash32(byte[], int, int, int)
  822.      * @deprecated Use {@link #hash32x86(byte[], int, int, int)} with the bytes returned from
  823.      * {@link String#getBytes(java.nio.charset.Charset)}. This corrects the processing of trailing bytes.
  824.      */
  825.     @Deprecated
  826.     public static int hash32(final String data) {
  827.         final byte[] bytes = StringUtils.getBytesUtf8(data);
  828.         return hash32(bytes, 0, bytes.length, DEFAULT_SEED);
  829.     }

  830.     /**
  831.      * Generates 32-bit hash from the byte array with a seed of zero.
  832.      * This is a helper method that will produce the same result as:
  833.      *
  834.      * <pre>
  835.      * int offset = 0;
  836.      * int seed = 0;
  837.      * int hash = MurmurHash3.hash32x86(data, offset, data.length, seed);
  838.      * </pre>
  839.      *
  840.      * @param data The input byte array
  841.      * @return The 32-bit hash
  842.      * @see #hash32x86(byte[], int, int, int)
  843.      * @since 1.14
  844.      */
  845.     public static int hash32x86(final byte[] data) {
  846.         return hash32x86(data, 0, data.length, 0);
  847.     }

  848.     /**
  849.      * Generates 32-bit hash from the byte array with the given offset, length and seed.
  850.      *
  851.      * <p>
  852.      * This is an implementation of the 32-bit hash function {@code MurmurHash3_x86_32}
  853.      * from Austin Appleby's original MurmurHash3 {@code c++} code in SMHasher.
  854.      * </p>
  855.      *
  856.      * @param data The input byte array
  857.      * @param offset The offset of data
  858.      * @param length The length of array
  859.      * @param seed The initial seed value
  860.      * @return The 32-bit hash
  861.      * @since 1.14
  862.      */
  863.     public static int hash32x86(final byte[] data, final int offset, final int length, final int seed) {
  864.         int hash = seed;
  865.         final int nblocks = length >> 2;
  866.         // body
  867.         for (int i = 0; i < nblocks; i++) {
  868.             final int index = offset + (i << 2);
  869.             final int k = MurmurHash.getLittleEndianInt(data, index);
  870.             hash = mix32(k, hash);
  871.         }
  872.         // tail
  873.         final int index = offset + (nblocks << 2);
  874.         int k1 = 0;
  875.         switch (offset + length - index) {
  876.         case 3:
  877.             k1 ^= (data[index + 2] & 0xff) << 16;
  878.             // falls-through
  879.         case 2:
  880.             // falls-through
  881.             k1 ^= (data[index + 1] & 0xff) << 8;
  882.             // falls-through
  883.         case 1:
  884.             k1 ^= data[index] & 0xff;
  885.             // mix functions
  886.             k1 *= C1_32;
  887.             k1 = Integer.rotateLeft(k1, R1_32);
  888.             k1 *= C2_32;
  889.             hash ^= k1;
  890.         }
  891.         hash ^= length;
  892.         return fmix32(hash);
  893.     }

  894.     /**
  895.      * Generates 64-bit hash from a byte array with a default seed.
  896.      *
  897.      * <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
  898.      *
  899.      * <p>
  900.      * This is a Murmur3-like 64-bit variant.
  901.      * The method does not produce the same result as either half of the hash bytes from
  902.      * {@linkplain #hash128x64(byte[])} with the same byte data.
  903.      * This method will be removed in a future release.
  904.      * </p>
  905.      *
  906.      * <p>
  907.      * Note: The sign extension bug in {@link #hash64(byte[], int, int, int)} does not effect
  908.      * this result as the default seed is positive.
  909.      * </p>
  910.      *
  911.      * <p>
  912.      * This is a helper method that will produce the same result as:
  913.      * </p>
  914.      *
  915.      * <pre>
  916.      * int offset = 0;
  917.      * int seed = 104729;
  918.      * long hash = MurmurHash3.hash64(data, offset, data.length, seed);
  919.      * </pre>
  920.      *
  921.      * @param data The input byte array
  922.      * @return The 64-bit hash
  923.      * @see #hash64(byte[], int, int, int)
  924.      * @deprecated Not part of the MurmurHash3 implementation.
  925.      * Use half of the hash bytes from {@link #hash128x64(byte[])}.
  926.      */
  927.     @Deprecated
  928.     public static long hash64(final byte[] data) {
  929.         return hash64(data, 0, data.length, DEFAULT_SEED);
  930.     }

  931.     /**
  932.      * Generates 64-bit hash from a byte array with the given offset and length and a default seed.
  933.      *
  934.      * <p><strong>
  935.      * This is not part of the original MurmurHash3 {@code c++} implementation.
  936.      * </strong></p>
  937.      *
  938.      * <p>
  939.      * This is a Murmur3-like 64-bit variant.
  940.      * The method does not produce the same result as either half of the hash bytes from
  941.      * {@linkplain #hash128x64(byte[])} with the same byte data.
  942.      * This method will be removed in a future release.
  943.      * </p>
  944.      *
  945.      * <p>
  946.      * Note: The sign extension bug in {@link #hash64(byte[], int, int, int)} does not effect
  947.      * this result as the default seed is positive.
  948.      * </p>
  949.      *
  950.      * <p>
  951.      * This is a helper method that will produce the same result as:
  952.      * </p>
  953.      *
  954.      * <pre>
  955.      * int seed = 104729;
  956.      * long hash = MurmurHash3.hash64(data, offset, length, seed);
  957.      * </pre>
  958.      *
  959.      * @param data The input byte array
  960.      * @param offset The offset of data
  961.      * @param length The length of array
  962.      * @return The 64-bit hash
  963.      * @see #hash64(byte[], int, int, int)
  964.      * @deprecated Not part of the MurmurHash3 implementation.
  965.      * Use half of the hash bytes from {@link #hash128x64(byte[], int, int, int)}.
  966.      */
  967.     @Deprecated
  968.     public static long hash64(final byte[] data, final int offset, final int length) {
  969.         return hash64(data, offset, length, DEFAULT_SEED);
  970.     }

  971.     /**
  972.      * Generates 64-bit hash from a byte array with the given offset, length and seed.
  973.      *
  974.      * <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
  975.      *
  976.      * <p>
  977.      * This is a Murmur3-like 64-bit variant.
  978.      * This method will be removed in a future release.
  979.      * </p>
  980.      *
  981.      * <p>
  982.      * This implementation contains a sign-extension bug in the seed initialization.
  983.      * This manifests if the seed is negative.
  984.      * </p>
  985.      *
  986.      * <p>
  987.      * This algorithm processes 8 bytes chunks of data in a manner similar to the 16 byte chunks
  988.      * of data processed in the MurmurHash3 {@code MurmurHash3_x64_128} method. However the hash
  989.      * is not mixed with a hash chunk from the next 8 bytes of data. The method will not return
  990.      * the same value as the first or second 64-bits of the function
  991.      * {@link #hash128(byte[], int, int, int)}.
  992.      * </p>
  993.      *
  994.      * <p>
  995.      * Use of this method is not advised. Use the first long returned from
  996.      * {@link #hash128x64(byte[], int, int, int)}.
  997.      * </p>
  998.      *
  999.      * @param data The input byte array
  1000.      * @param offset The offset of data
  1001.      * @param length The length of array
  1002.      * @param seed The initial seed value
  1003.      * @return The 64-bit hash
  1004.      * @deprecated Not part of the MurmurHash3 implementation.
  1005.      * Use half of the hash bytes from {@link #hash128x64(byte[], int, int, int)}.
  1006.      */
  1007.     @Deprecated
  1008.     public static long hash64(final byte[] data, final int offset, final int length, final int seed) {
  1009.         // Note: This fails to apply masking using 0xffffffffL to the seed.
  1010.         long hash = seed;
  1011.         final int nblocks = length >> 3;
  1012.         // body
  1013.         for (int i = 0; i < nblocks; i++) {
  1014.             final int index = offset + (i << 3);
  1015.             long k = MurmurHash.getLittleEndianLong(data, index);
  1016.             // mix functions
  1017.             k *= C1;
  1018.             k = Long.rotateLeft(k, R1);
  1019.             k *= C2;
  1020.             hash ^= k;
  1021.             hash = Long.rotateLeft(hash, R2) * M + N1;
  1022.         }
  1023.         // tail
  1024.         long k1 = 0;
  1025.         final int index = offset + (nblocks << 3);
  1026.         switch (offset + length - index) {
  1027.         case 7:
  1028.             k1 ^= ((long) data[index + 6] & 0xff) << 48;
  1029.             // falls-through
  1030.         case 6:
  1031.             k1 ^= ((long) data[index + 5] & 0xff) << 40;
  1032.             // falls-through
  1033.         case 5:
  1034.             k1 ^= ((long) data[index + 4] & 0xff) << 32;
  1035.             // falls-through
  1036.         case 4:
  1037.             k1 ^= ((long) data[index + 3] & 0xff) << 24;
  1038.             // falls-through
  1039.         case 3:
  1040.             k1 ^= ((long) data[index + 2] & 0xff) << 16;
  1041.             // falls-through
  1042.         case 2:
  1043.             k1 ^= ((long) data[index + 1] & 0xff) << 8;
  1044.             // falls-through
  1045.         case 1:
  1046.             k1 ^= (long) data[index] & 0xff;
  1047.             k1 *= C1;
  1048.             k1 = Long.rotateLeft(k1, R1);
  1049.             k1 *= C2;
  1050.             hash ^= k1;
  1051.         }
  1052.         // finalization
  1053.         hash ^= length;
  1054.         return fmix64(hash);
  1055.     }

  1056.     /**
  1057.      * Generates 64-bit hash from an int with a default seed.
  1058.      *
  1059.      * <p><strong>
  1060.      * This is not part of the original MurmurHash3 {@code c++} implementation.
  1061.      * </strong></p>
  1062.      *
  1063.      * <p>
  1064.      * This is a Murmur3-like 64-bit variant.
  1065.      * The method does not produce the same result as either half of the hash bytes from
  1066.      * {@linkplain #hash128x64(byte[])} with the same byte data from the {@code int}.
  1067.      * This method will be removed in a future release.
  1068.      * </p>
  1069.      *
  1070.      * <p>
  1071.      * Note: The sign extension bug in {@link #hash64(byte[], int, int, int)} does not effect
  1072.      * this result as the default seed is positive.
  1073.      * </p>
  1074.      *
  1075.      * <p>
  1076.      * This is a helper method that will produce the same result as:
  1077.      * </p>
  1078.      *
  1079.      * <pre>
  1080.      * int offset = 0;
  1081.      * int seed = 104729;
  1082.      * long hash = MurmurHash3.hash64(ByteBuffer.allocate(4)
  1083.      *                                          .putInt(data)
  1084.      *                                          .array(), offset, 4, seed);
  1085.      * </pre>
  1086.      *
  1087.      * @param data The int to hash
  1088.      * @return The 64-bit hash
  1089.      * @see #hash64(byte[], int, int, int)
  1090.      * @deprecated Not part of the MurmurHash3 implementation.
  1091.      * Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code int}.
  1092.      */
  1093.     @Deprecated
  1094.     public static long hash64(final int data) {
  1095.         long k1 = Integer.reverseBytes(data) & -1L >>> 32;
  1096.         long hash = DEFAULT_SEED;
  1097.         k1 *= C1;
  1098.         k1 = Long.rotateLeft(k1, R1);
  1099.         k1 *= C2;
  1100.         hash ^= k1;
  1101.         // finalization
  1102.         hash ^= Integer.BYTES;
  1103.         return fmix64(hash);
  1104.     }

  1105.     /**
  1106.      * Generates 64-bit hash from a long with a default seed.
  1107.      *
  1108.      * <p><strong>
  1109.      * This is not part of the original MurmurHash3 {@code c++} implementation.
  1110.      * </strong></p>
  1111.      *
  1112.      * <p>
  1113.      * This is a Murmur3-like 64-bit variant.
  1114.      * The method does not produce the same result as either half of the hash bytes from
  1115.      * {@linkplain #hash128x64(byte[])} with the same byte data from the {@code long}.
  1116.      * This method will be removed in a future release.
  1117.      * </p>
  1118.      *
  1119.      * <p>
  1120.      * Note: The sign extension bug in {@link #hash64(byte[], int, int, int)} does not effect
  1121.      * this result as the default seed is positive.
  1122.      * </p>
  1123.      *
  1124.      * <p>
  1125.      * This is a helper method that will produce the same result as:
  1126.      * </p>
  1127.      *
  1128.      * <pre>
  1129.      * int offset = 0;
  1130.      * int seed = 104729;
  1131.      * long hash = MurmurHash3.hash64(ByteBuffer.allocate(8)
  1132.      *                                          .putLong(data)
  1133.      *                                          .array(), offset, 8, seed);
  1134.      * </pre>
  1135.      *
  1136.      * @param data The long to hash
  1137.      * @return The 64-bit hash
  1138.      * @see #hash64(byte[], int, int, int)
  1139.      * @deprecated Not part of the MurmurHash3 implementation.
  1140.      * Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code long}.
  1141.      */
  1142.     @Deprecated
  1143.     public static long hash64(final long data) {
  1144.         long hash = DEFAULT_SEED;
  1145.         long k = Long.reverseBytes(data);
  1146.         // mix functions
  1147.         k *= C1;
  1148.         k = Long.rotateLeft(k, R1);
  1149.         k *= C2;
  1150.         hash ^= k;
  1151.         hash = Long.rotateLeft(hash, R2) * M + N1;
  1152.         // finalization
  1153.         hash ^= Long.BYTES;
  1154.         return fmix64(hash);
  1155.     }

  1156.     /**
  1157.      * Generates 64-bit hash from a short with a default seed.
  1158.      *
  1159.      * <p><strong>This is not part of the original MurmurHash3 {@code c++} implementation.</strong></p>
  1160.      *
  1161.      * <p>
  1162.      * This is a Murmur3-like 64-bit variant.
  1163.      * The method does not produce the same result as either half of the hash bytes from
  1164.      * {@linkplain #hash128x64(byte[])} with the same byte data from the {@code short}.
  1165.      * This method will be removed in a future release.
  1166.      * </p>
  1167.      *
  1168.      * <p>
  1169.      * Note: The sign extension bug in {@link #hash64(byte[], int, int, int)} does not effect
  1170.      * this result as the default seed is positive.
  1171.      * </p>
  1172.      *
  1173.      * <p>
  1174.      * This is a helper method that will produce the same result as:
  1175.      * </p>
  1176.      *
  1177.      * <pre>
  1178.      * int offset = 0;
  1179.      * int seed = 104729;
  1180.      * long hash = MurmurHash3.hash64(ByteBuffer.allocate(2)
  1181.      *                                          .putShort(data)
  1182.      *                                          .array(), offset, 2, seed);
  1183.      * </pre>
  1184.      *
  1185.      * @param data The short to hash
  1186.      * @return The 64-bit hash
  1187.      * @see #hash64(byte[], int, int, int)
  1188.      * @deprecated Not part of the MurmurHash3 implementation.
  1189.      * Use half of the hash bytes from {@link #hash128x64(byte[])} with the bytes from the {@code short}.
  1190.      */
  1191.     @Deprecated
  1192.     public static long hash64(final short data) {
  1193.         long hash = DEFAULT_SEED;
  1194.         long k1 = 0;
  1195.         k1 ^= ((long) data & 0xff) << 8;
  1196.         k1 ^= (long) ((data & 0xFF00) >> 8) & 0xff;
  1197.         k1 *= C1;
  1198.         k1 = Long.rotateLeft(k1, R1);
  1199.         k1 *= C2;
  1200.         hash ^= k1;

  1201.         // finalization
  1202.         hash ^= Short.BYTES;
  1203.         return fmix64(hash);
  1204.     }

  1205.     /**
  1206.      * Performs the intermediate mix step of the 32-bit hash function {@code MurmurHash3_x86_32}.
  1207.      *
  1208.      * @param k The data to add to the hash
  1209.      * @param hash The current hash
  1210.      * @return The new hash
  1211.      */
  1212.     private static int mix32(int k, int hash) {
  1213.         k *= C1_32;
  1214.         k = Integer.rotateLeft(k, R1_32);
  1215.         k *= C2_32;
  1216.         hash ^= k;
  1217.         return Integer.rotateLeft(hash, R2_32) * M_32 + N_32;
  1218.     }

  1219.     /** No instance methods. */
  1220.     private MurmurHash3() {
  1221.     }
  1222. }