Class HastyPointHash

java.lang.Object
squidpony.squidmath.IPointHash.LongImpl
squidpony.squidmath.HastyPointHash
All Implemented Interfaces:
IPointHash

public final class HastyPointHash
extends IPointHash.LongImpl
A group of similar methods for getting hashes of points based on long coordinates in 2, 3, 4, or 6 dimensions and a long for state; like PointHash but faster and maybe not as high-quality. This implementation has high enough quality to be useful as a source of random numbers based on positions, but would likely not be a good option in a hash table (or at least not as good as the tailored implementation of Coord.hashCode(), for instance). At low dimensions, this is a little faster than PointHash, but this class doesn't slow down much at all as more dimensions are used, while PointHash and most other implementations do slow down. You can also consider IntPointHash if your input and output types are usually int, since it's even faster.
This implements IPointHash and has a long it uses internally for state, exposed by getState().
  • 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.LongImpl

    state
  • Constructor Summary

    Constructors 
    Constructor Description
    HastyPointHash()  
  • Method Summary

    Modifier and Type Method Description
    long getState()  
    static int hash256​(long x, long y, long s)
    Gets an 8-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long.
    static int hash256​(long x, long y, long z, long s)
    Gets an 8-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long.
    static int hash256​(long x, long y, long z, long w, long s)
    Gets an 8-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long.
    static int hash256​(long x, long y, long z, long w, long u, long v, long s)
    Gets an 8-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long.
    static int hash256_alt​(long x, long y, long z, long w, long seed)  
    static int hash32​(long x, long y, long s)
    Gets a 5-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long.
    static int hash32​(long x, long y, long z, long s)
    Gets a 5-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long.
    static int hash32​(long x, long y, long z, long w, long s)
    Gets a 5-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long.
    static int hash32​(long x, long y, long z, long w, long u, long v, long s)
    Gets a 5-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long.
    static int hash64​(long x, long y, long s)
    Gets a 6-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long.
    static int hash64​(long x, long y, long z, long s)
    Gets a 6-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long.
    static int hash64​(long x, long y, long z, long w, long s)
    Gets a 6-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long.
    static int hash64​(long x, long y, long z, long w, long u, long v, long s)
    Gets a 6-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long.
    static long hashAll​(long x, long y, long s)
    Gets a 64-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long.
    static long hashAll​(long x, long y, long z, long s)
    Gets a 64-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long.
    static long hashAll​(long x, long y, long z, long w, long s)
    Gets a 64-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long.
    static long hashAll​(long x, long y, long z, long w, long u, long v, long s)
    Gets a 64-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long.
    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.LongImpl

    hash, hash, hash, hash, setState, 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)
    • getState

      public long getState()
    • hashAll

      public static long hashAll​(long x, long y, long s)
      Gets a 64-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      s - the state/seed; any long
      Returns:
      64-bit hash of the x,y point with the given state
    • hashAll

      public static long hashAll​(long x, long y, long z, long s)
      Gets a 64-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      s - the state/seed; any long
      Returns:
      64-bit hash of the x,y,z point with the given state
    • hashAll

      public static long hashAll​(long x, long y, long z, long w, long s)
      Gets a 64-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      s - the state; any long
      Returns:
      64-bit hash of the x,y,z,w point with the given state
    • hashAll

      public static long hashAll​(long x, long y, long z, long w, long u, long v, long s)
      Gets a 64-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      u - u position; any long
      v - v position; any long
      s - the state; any long
      Returns:
      64-bit hash of the x,y,z,w,u,v point with the given state
    • hash256

      public static int hash256​(long x, long y, long s)
      Gets an 8-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      s - the state/seed; any long
      Returns:
      8-bit hash of the x,y point with the given state
    • hash256

      public static int hash256​(long x, long y, long z, long s)
      Gets an 8-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      s - the state/seed; any long
      Returns:
      8-bit hash of the x,y,z point with the given state
    • hash256

      public static int hash256​(long x, long y, long z, long w, long s)
      Gets an 8-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      s - the state; any long
      Returns:
      8-bit hash of the x,y,z,w point with the given state
    • hash256

      public static int hash256​(long x, long y, long z, long w, long u, long v, long s)
      Gets an 8-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      u - u position; any long
      v - v position; any long
      s - the state; any long
      Returns:
      8-bit hash of the x,y,z,w,u,v point with the given state
    • hash32

      public static int hash32​(long x, long y, long s)
      Gets a 5-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      s - the state/seed; any long
      Returns:
      5-bit hash of the x,y point with the given state
    • hash32

      public static int hash32​(long x, long y, long z, long s)
      Gets a 5-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      s - the state/seed; any long
      Returns:
      5-bit hash of the x,y,z point with the given state
    • hash32

      public static int hash32​(long x, long y, long z, long w, long s)
      Gets a 5-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      s - the state; any long
      Returns:
      5-bit hash of the x,y,z,w point with the given state
    • hash32

      public static int hash32​(long x, long y, long z, long w, long u, long v, long s)
      Gets a 5-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      u - u position; any long
      v - v position; any long
      s - the state; any long
      Returns:
      5-bit hash of the x,y,z,w,u,v point with the given state
    • hash64

      public static int hash64​(long x, long y, long s)
      Gets a 6-bit point hash of a 2D point (x and y are both longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      s - the state/seed; any long
      Returns:
      6-bit hash of the x,y point with the given state
    • hash64

      public static int hash64​(long x, long y, long z, long s)
      Gets a 6-bit point hash of a 3D point (x, y, and z are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      s - the state/seed; any long
      Returns:
      6-bit hash of the x,y,z point with the given state
    • hash64

      public static int hash64​(long x, long y, long z, long w, long s)
      Gets a 6-bit point hash of a 4D point (x, y, z, and w are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      s - the state; any long
      Returns:
      6-bit hash of the x,y,z,w point with the given state
    • hash64

      public static int hash64​(long x, long y, long z, long w, long u, long v, long s)
      Gets a 6-bit point hash of a 6D point (x, y, z, w, u, and v are all longs) and a state/seed as a long. This point hash has close to the best speed of any algorithms tested, and though its quality is mediocre for traditional uses of hashing (such as hash tables), it's sufficiently random to act as a positional RNG.
      This uses a technique related to the one used by Martin Roberts for his golden-ratio-based sub-random sequences, where each axis is multiplied by a different constant, and the choice of constants depends on the number of axes but is always related to a generalized form of golden ratios, repeatedly dividing 1.0 by the generalized ratio. See Roberts' article for some more information on how he uses this, but we do things differently because we want random-seeming results instead of separated sub-random results.
      Parameters:
      x - x position; any long
      y - y position; any long
      z - z position; any long
      w - w position; any long
      u - u position; any long
      v - v position; any long
      s - the state; any long
      Returns:
      6-bit hash of the x,y,z,w,u,v point with the given state
    • hash256_alt

      public static int hash256_alt​(long x, long y, long z, long w, long seed)