Package squidpony.squidmath
Class IntPointHash
java.lang.Object
squidpony.squidmath.IPointHash.IntImpl
squidpony.squidmath.IntPointHash
- All Implemented Interfaces:
IPointHash
public final class IntPointHash extends IPointHash.IntImpl
A group of similar methods for getting hashes of points based on int coordinates in 2, 3, 4, or 6 dimensions and
an int for state; the code is similar to
Getting the bottom 24 bits of
HastyPointHash
but will be much faster on GWT. 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()
; it is still better than Objects.hash(Object...)
). Even on a desktop
JVM, this class is faster than PointHash
or HastyPointHash
. The technique used here
owes credit to Pelle Evensen for finding the significant quality increase from using multiple bitwise rotations XORed
together, and Martin Roberts for discovering the connection between higher dimensional ranks and the appropriate
numbers to gain similar qualities to adding the golden ratio mod 1 in 1D, using what had already been named
"harmonious numbers." The only case where this can return different results on GWT than on a desktop or mobile
JVM is when the inputs are GWT-specific out-of-range JS Numbers appearing to be ints, and that's a problem with
the input rather than the algorithm.
Getting the bottom 24 bits of
hashAll(int, int, int)
, dividing to get a float from 0 to 1, and graphing
it produces this white-noise-like image. The frequency magnitude of
that image is this diagram, which looks almost exactly like
a diagram of the frequency magnitude of white noise. This shows
there are effectively no significant structural artifacts in the noise when interpreted as a float.-
Nested Class Summary
Nested classes/interfaces inherited from interface squidpony.squidmath.IPointHash
IPointHash.IntImpl, IPointHash.LongImpl
-
Field Summary
-
Constructor Summary
Constructors Constructor Description IntPointHash()
-
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 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
hashAll(int x, int y, int z, int s)
A 32-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
hashAll(int x, int y, int z, int w, int s)
A 32-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
hashAll(int x, int y, int z, int w, int u, int v, int s)
A 32-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.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)
-
Constructor Details
-
IntPointHash
public IntPointHash()
-
-
Method Details
-
hashWithState
-
hashWithState
-
hashWithState
-
hashWithState
-
hashAll
A 32-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 inty
- y position, as an ints
- 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
A 32-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 inty
- y position, as an intz
- z position, as an ints
- 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
A 32-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 inty
- y position, as an intz
- z position, as an intw
- w position, as an ints
- 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
A 32-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 inty
- y position, as an intz
- z position, as an intw
- w position, as an intu
- u position, as an intv
- v position, as an ints
- 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
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 inty
- y position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an intu
- u position, as an intv
- v position, as an ints
- 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
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 inty
- y position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an intu
- u position, as an intv
- v position, as an ints
- 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
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 inty
- y position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an ints
- 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
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 inty
- y position, as an intz
- z position, as an intw
- w position, as an intu
- u position, as an intv
- v position, as an ints
- 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
-