Java Hash Calculate hash(Object key, int limit)

Here you can find the source of hash(Object key, int limit)

Description

hash

License

Open Source License

Declaration

public static int hash(Object key, int limit) 

Method Source Code

//package com.java2s;
/*/*from   w w  w  .  ja v a 2  s .  c  om*/
 *
 *  The contents of this file are subject to the Terracotta Public 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://terracotta.org/legal/terracotta-public-license.
 *
 *  Software distributed under the License is distributed on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 *  the specific language governing rights and limitations under the License.
 *
 *  The Covered Software is Terracotta Core.
 *
 *  The Initial Developer of the Covered Software is
 *  Terracotta, Inc., a Software AG company
 *
 */

public class Main {
    public static int hash(Object key, int limit) {
        if (limit == 1) {
            return 0;
        }
        int hashValue = hash(key.hashCode());
        if (hashValue == Integer.MIN_VALUE) {
            hashValue -= 1;
        }
        hashValue = Math.abs(hashValue);
        return hashValue % limit;
    }

    private static int hash(int h) {
        h += ~(h << 9);
        h ^= (h >>> 14);
        h += (h << 4);
        h ^= (h >>> 10);
        return h;
    }
}

Related

  1. hash(int value)
  2. hash(int x, int y)
  3. hash(long key)
  4. hash(long mover, long enemy)
  5. hash(Object a, Object b)
  6. hash(Object o)
  7. hash(Object obj)
  8. hash(Object obj)
  9. hash(Object obj)