Class PointHash

All Implemented Interfaces:
IPointHash

public final class PointHash
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. Internally, the methods here are based on a simplified version of Hive from CrossHash; this version does not include the somewhat-involved finalization step. Omitting finalization helps this class be somewhat faster, but also makes it so it doesn't avalanche very well. Avalanche refers to the property of a hash where one changed bit in the input(s) or state has a chance to change any of the output's bits, and should usually change about 50% of them. You can call avalanche(long) on the result of a hashAll() call to put the finalization step back. This has rather good quality when avalanche(long) is used, but most usage will not be able to discern a difference between the quality of this (with or without avalanche) and the quality of HastyPointHash, where HastyPointHash is a fair amount faster. If your state and input are ints anyway, consider IntPointHash, since it's faster than the long-based hashes and still has perfectly fine quality.
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
    PointHash()  
  • Method Summary

    Modifier and Type Method Description
    static long avalanche​(long state)
    If it's important for some usage that one bit of change in any parameters cause roughly 50% of all bits in the result to change, then you can call this on the output of any hashAll() overload to improve the bit avalanche qualities.
    long getState()  
    static int hash256​(long x, long y, long state)  
    static int hash256​(long x, long y, long z, long state)  
    static int hash256​(long x, long y, long z, long w, long state)  
    static int hash256​(long x, long y, long z, long w, long u, long v, long state)  
    static int hash32​(long x, long y, long state)  
    static int hash32​(long x, long y, long z, long state)  
    static int hash32​(long x, long y, long z, long w, long state)  
    static int hash32​(long x, long y, long z, long w, long u, long v, long state)  
    static int hash64​(long x, long y, long state)  
    static int hash64​(long x, long y, long z, long state)  
    static int hash64​(long x, long y, long z, long w, long state)  
    static int hash64​(long x, long y, long z, long w, long u, long v, long state)  
    static long hashAll​(long x, long y, long state)  
    static long hashAll​(long x, long y, long z, long state)  
    static long hashAll​(long x, long y, long z, long w, long state)  
    static long hashAll​(long x, long y, long z, long w, long u, long v, long state)  
    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()
    • avalanche

      public static long avalanche​(long state)
      If it's important for some usage that one bit of change in any parameters cause roughly 50% of all bits in the result to change, then you can call this on the output of any hashAll() overload to improve the bit avalanche qualities.
      Parameters:
      state - the output of hashAll() in this class
      Returns:
      a significantly-mixed-around long obtained from state
    • hashAll

      public static long hashAll​(long x, long y, long state)
      Parameters:
      x -
      y -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      u -
      v -
      state -
      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 state)
      Parameters:
      x -
      y -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      u -
      v -
      state -
      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 state)
      Parameters:
      x -
      y -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      u -
      v -
      state -
      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 state)
      Parameters:
      x -
      y -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      state -
      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 state)
      Parameters:
      x -
      y -
      z -
      w -
      u -
      v -
      state -
      Returns:
      6-bit hash of the x,y,z,w,u,v point with the given state