Class GoldPointHash

java.lang.Object
squidpony.squidmath.IPointHash.IntImpl
squidpony.squidmath.GoldPointHash
All Implemented Interfaces:
IPointHash

public final class GoldPointHash
extends IPointHash.IntImpl
A relatively simple IPointHash that multiplies each of the x, y, etc. components and the state by a different constant for each (a "harmonious number" related to the golden ratio), sums them, and keeps only the upper bits. This benefits from dot-product optimizations performed by recent JVMs (since at least Java 8). It finishes each hash with an XLCG step to improve the upper bits, then it right-shifts the whole long so it fits in the desired output range (such as 8 bits for hash256(int, int, int)), casts it to int and returns that.
This hash is slightly faster for some noise applications than IntPointHash, and has comparable quality, but does require a lot of math on long values, and that can be quite slow on GWT. This should probably be used primarily on desktop targets, and/or maybe mobile.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface squidpony.squidmath.IPointHash

    IPointHash.IntImpl, IPointHash.LongImpl
  • Field Summary

    Fields inherited from class squidpony.squidmath.IPointHash.IntImpl

    state
  • Constructor Summary

    Constructors 
    Constructor Description
    GoldPointHash()  
  • Method Summary

    Modifier and Type Method Description
    static int hash256​(int x, int y, int s)
    A 8-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash256​(int x, int y, int z, int s)
    A 8-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash256​(int x, int y, int z, int w, int s)
    A 8-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash256​(int x, int y, int z, int w, int u, int v, int s)
    A 8-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash32​(int x, int y, int s)
    A 5-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash32​(int x, int y, int z, int s)
    A 5-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash32​(int x, int y, int z, int w, int s)
    A 5-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash32​(int x, int y, int z, int w, int u, int v, int s)
    A 5-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash64​(int x, int y, int s)
    A 6-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash64​(int x, int y, int z, int s)
    A 6-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash64​(int x, int y, int z, int w, int s)
    A 6-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hash64​(int x, int y, int z, int w, int u, int v, int s)
    A 6-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it.
    static int hashAll​(int x, int y, int s)
    A 32-bit-result point hash that uses multiplication with long constants.
    static int hashAll​(int x, int y, int z, int s)
    A 32-bit-result point hash that uses multiplication with long constants.
    static int hashAll​(int x, int y, int z, int w, int s)
    A 32-bit-result point hash that uses multiplication with long constants.
    static int hashAll​(int x, int y, int z, int w, int u, int v, int s)
    A 32-bit-result point hash that uses multiplication with long constants.
    int hashWithState​(int x, int y, int state)  
    int hashWithState​(int x, int y, int z, int state)  
    int hashWithState​(int x, int y, int z, int w, int state)  
    int hashWithState​(int x, int y, int z, int w, int u, int v, int state)  

    Methods inherited from class squidpony.squidmath.IPointHash.IntImpl

    hash, hash, hash, hash, setState

    Methods inherited from class java.lang.Object

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

  • Method Details

    • hashWithState

      public int hashWithState​(int x, int y, int state)
    • hashWithState

      public int hashWithState​(int x, int y, int z, int state)
    • hashWithState

      public int hashWithState​(int x, int y, int z, int w, int state)
    • hashWithState

      public int hashWithState​(int x, int y, int z, int w, int u, int v, int state)
    • hashAll

      public static int hashAll​(int x, int y, int s)
      A 32-bit-result point hash that uses multiplication with long constants.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      32-bit hash of the x,y point with the given state s
    • hashAll

      public static int hashAll​(int x, int y, int z, int s)
      A 32-bit-result point hash that uses multiplication with long constants.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      32-bit hash of the x,y,z point with the given state s
    • hashAll

      public static int hashAll​(int x, int y, int z, int w, int s)
      A 32-bit-result point hash that uses multiplication with long constants.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      32-bit hash of the x,y,z,w point with the given state s
    • hashAll

      public static int hashAll​(int x, int y, int z, int w, int u, int v, int s)
      A 32-bit-result point hash that uses multiplication with long constants.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      u - u position, as an int
      v - v position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      32-bit hash of the x,y,z,w,u,v point with the given state s
    • hash256

      public static int hash256​(int x, int y, int s)
      A 8-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      8-bit hash of the x,y point with the given state s
    • hash256

      public static int hash256​(int x, int y, int z, int s)
      A 8-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      8-bit hash of the x,y,z point with the given state s
    • hash256

      public static int hash256​(int x, int y, int z, int w, int s)
      A 8-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      8-bit hash of the x,y,z,w point with the given state s
    • hash256

      public static int hash256​(int x, int y, int z, int w, int u, int v, int s)
      A 8-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      u - u position, as an int
      v - v position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      8-bit hash of the x,y,z,w,u,v point with the given state s
    • hash64

      public static int hash64​(int x, int y, int s)
      A 6-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      6-bit hash of the x,y point with the given state s
    • hash64

      public static int hash64​(int x, int y, int z, int s)
      A 6-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      6-bit hash of the x,y,z point with the given state s
    • hash64

      public static int hash64​(int x, int y, int z, int w, int s)
      A 6-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      6-bit hash of the x,y,z,w point with the given state s
    • hash64

      public static int hash64​(int x, int y, int z, int w, int u, int v, int s)
      A 6-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      u - u position, as an int
      v - v position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      6-bit hash of the x,y,z,w,u,v point with the given state s
    • hash32

      public static int hash32​(int x, int y, int s)
      A 5-bit point hash that smashes x and y into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      5-bit hash of the x,y point with the given state s
    • hash32

      public static int hash32​(int x, int y, int z, int s)
      A 5-bit point hash that smashes x, y, and z into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      5-bit hash of the x,y,z point with the given state s
    • hash32

      public static int hash32​(int x, int y, int z, int w, int s)
      A 5-bit point hash that smashes x, y, z, and w into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      5-bit hash of the x,y,z,w point with the given state s
    • hash32

      public static int hash32​(int x, int y, int z, int w, int u, int v, int s)
      A 5-bit point hash that smashes x, y, z, w, u, and v into s using XOR and multiplications by harmonious numbers, then runs a simple unary hash on s and returns it. Has better performance than HastyPointHash, especially for ints, and has slightly fewer collisions in a hash table of points. GWT-optimized. Inspired by Pelle Evensen's rrxmrrxmsx_0 unary hash, though this doesn't use its code or its full algorithm. The unary hash used here has been stripped down heavily, both for speed and because unless points are selected specifically to target flaws in the hash, it doesn't need the intense resistance to bad inputs that rrxmrrxmsx_0 has.
      Parameters:
      x - x position, as an int
      y - y position, as an int
      z - z position, as an int
      w - w position, as an int
      u - u position, as an int
      v - v position, as an int
      s - any int, a seed to be able to produce many hashes for a given point
      Returns:
      5-bit hash of the x,y,z,w,u,v point with the given state s