Java Hash Code Calculate hashcode(final int[] array)

Here you can find the source of hashcode(final int[] array)

Description

Computes a hashcode for an integer array, partially unrolled.

License

Apache License

Parameter

Parameter Description
array a parameter

Return

the hashcode

Declaration

public static final int hashcode(final int[] array) 

Method Source Code

//package com.java2s;
/*//from  w  ww . ja  v a 2 s  .  c  om
 * ARX: Powerful Data Anonymization
 * Copyright 2012 - 2016 Fabian Prasser, Florian Kohlmayer and contributors
 * 
 * Licensed 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.
 */

public class Main {
    /**
     * Computes a hashcode for an integer array, partially unrolled.
     * 
     * @param array
     * @return the hashcode
     */
    public static final int hashcode(final int[] array) {
        final int len = array.length;
        int result = 23;
        int i = 0;
        // Do blocks of four ints unrolled.
        for (; (i + 3) < len; i += 4) {
            result = (1874161 * result) + // 37 * 37 * 37 * 37 
                    (50653 * array[i]) + // 37 * 37 * 37
                    (1369 * array[i + 1]) + // 37 * 37
                    (37 * array[i + 2]) + array[i + 3];
        }
        // Do the rest
        for (; i < len; i++) {
            result = (37 * result) + array[i];
        }
        return result;
    }
}

Related

  1. hashCode(final char[] text, final int textOffset, final int textLen)
  2. hashCode(final int i)
  3. hashCode(final int i)
  4. hashCode(final int seed, final int hashcode)
  5. hashCode(final int x, final int y)
  6. hashCode(final long l)
  7. hashCode(final long l)
  8. hashCode(final long v)
  9. hashCode(final Object obj)