Class HashUtil

java.lang.Object
ca.spottedleaf.common.util.HashUtil

public final class HashUtil extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    hash(int x)
    A hash function for an int.
    static long
    hash(long x)
    A hash function for a long.
    static int
    invHash(int x)
    Inverses hash(int).
    static long
    invHash(long x)
    Inverses hash(long).
    static int
    invMix(int x)
    The inverse of mix(int).
    static long
    invMix(long x)
    The inverse of mix(long).
    static int
    mix(int x)
    Quickly mixes the bits of an integer.
    static long
    mix(long x)
    Quickly mixes the bits of a long integer.
    static int
    murmurHash3(int x)
    Avalanches the bits of an integer by applying the finalisation step of MurmurHash3.
    static long
    murmurHash3(long x)
    Avalanches the bits of a long integer by applying the finalisation step of MurmurHash3.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • murmurHash3

      public static int murmurHash3(int x)
      Avalanches the bits of an integer by applying the finalisation step of MurmurHash3.

      This method implements the finalisation step of Austin Appleby's MurmurHash3. Its purpose is to avalanche the bits of the argument to within 0.25% bias.

      Parameters:
      x - an integer.
      Returns:
      a hash value with good avalanching properties.
    • murmurHash3

      public static long murmurHash3(long x)
      Avalanches the bits of a long integer by applying the finalisation step of MurmurHash3.

      This method implements the finalisation step of Austin Appleby's MurmurHash3. Its purpose is to avalanche the bits of the argument to within 0.25% bias.

      Parameters:
      x - a long integer.
      Returns:
      a hash value with good avalanching properties.
    • mix

      public static int mix(int x)
      Quickly mixes the bits of an integer.

      This method mixes the bits of the argument by multiplying by the golden ratio and xorshifting the result. It is borrowed from Koloboke, and it has slightly worse behaviour than murmurHash3(int) (in open-addressing hash tables the average number of probes is slightly larger), but it's much faster.

      Parameters:
      x - an integer.
      Returns:
      a hash value obtained by mixing the bits of x.
      See Also:
    • invMix

      public static int invMix(int x)
      The inverse of mix(int). This method is mainly useful to create unit tests.
      Parameters:
      x - an integer.
      Returns:
      a value that passed through mix(int) would give x.
    • mix

      public static long mix(long x)
      Quickly mixes the bits of a long integer.

      This method mixes the bits of the argument by multiplying by the golden ratio and xorshifting twice the result. It is borrowed from Koloboke, and it has slightly worse behaviour than murmurHash3(long) (in open-addressing hash tables the average number of probes is slightly larger), but it's much faster.

      Parameters:
      x - a long integer.
      Returns:
      a hash value obtained by mixing the bits of x.
    • invMix

      public static long invMix(long x)
      The inverse of mix(long). This method is mainly useful to create unit tests.
      Parameters:
      x - a long integer.
      Returns:
      a value that passed through mix(long) would give x.
    • hash

      public static int hash(int x)
      A hash function for an int. This hash function is designed to be used to index into a hash table. There are no guarantees about how the hash is computed.
      Parameters:
      x - The input
      Returns:
      A hash for the input.
    • invHash

      public static int invHash(int x)
      Inverses hash(int). That is, x = invHash(hash(x)).
      Parameters:
      x - The input
      Returns:
      The inverse of hash(int).
    • hash

      public static long hash(long x)
      A hash function for a long. This hash function is designed to be used to index into a hash table. There are no guarantees about how the hash is computed.
      Parameters:
      x - The input
      Returns:
      A hash for the input.
    • invHash

      public static long invHash(long x)
      Inverses hash(long). That is, x = invHash(hash(x)).
      Parameters:
      x - The input
      Returns:
      The inverse of hash(long).