Package squidpony.squidmath
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
This implements
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
-
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)
-
Constructor Details
-
HastyPointHash
public HastyPointHash()
-
-
Method Details
-
hashWithState
-
hashWithState
-
hashWithState
-
hashWithState
-
getState
-
hashAll
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 longy
- y position; any longs
- the state/seed; any long- Returns:
- 64-bit hash of the x,y point with the given state
-
hashAll
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 longy
- y position; any longz
- z position; any longs
- the state/seed; any long- Returns:
- 64-bit hash of the x,y,z point with the given state
-
hashAll
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 longy
- y position; any longz
- z position; any longw
- w position; any longs
- the state; any long- Returns:
- 64-bit hash of the x,y,z,w point with the given state
-
hashAll
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 longy
- y position; any longz
- z position; any longw
- w position; any longu
- u position; any longv
- v position; any longs
- the state; any long- Returns:
- 64-bit hash of the x,y,z,w,u,v point with the given state
-
hash256
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 longy
- y position; any longs
- the state/seed; any long- Returns:
- 8-bit hash of the x,y point with the given state
-
hash256
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 longy
- y position; any longz
- z position; any longs
- the state/seed; any long- Returns:
- 8-bit hash of the x,y,z point with the given state
-
hash256
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 longy
- y position; any longz
- z position; any longw
- w position; any longs
- the state; any long- Returns:
- 8-bit hash of the x,y,z,w point with the given state
-
hash256
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 longy
- y position; any longz
- z position; any longw
- w position; any longu
- u position; any longv
- v position; any longs
- the state; any long- Returns:
- 8-bit hash of the x,y,z,w,u,v point with the given state
-
hash32
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 longy
- y position; any longs
- the state/seed; any long- Returns:
- 5-bit hash of the x,y point with the given state
-
hash32
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 longy
- y position; any longz
- z position; any longs
- the state/seed; any long- Returns:
- 5-bit hash of the x,y,z point with the given state
-
hash32
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 longy
- y position; any longz
- z position; any longw
- w position; any longs
- the state; any long- Returns:
- 5-bit hash of the x,y,z,w point with the given state
-
hash32
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 longy
- y position; any longz
- z position; any longw
- w position; any longu
- u position; any longv
- v position; any longs
- the state; any long- Returns:
- 5-bit hash of the x,y,z,w,u,v point with the given state
-
hash64
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 longy
- y position; any longs
- the state/seed; any long- Returns:
- 6-bit hash of the x,y point with the given state
-
hash64
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 longy
- y position; any longz
- z position; any longs
- the state/seed; any long- Returns:
- 6-bit hash of the x,y,z point with the given state
-
hash64
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 longy
- y position; any longz
- z position; any longw
- w position; any longs
- the state; any long- Returns:
- 6-bit hash of the x,y,z,w point with the given state
-
hash64
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 longy
- y position; any longz
- z position; any longw
- w position; any longu
- u position; any longv
- v position; any longs
- the state; any long- Returns:
- 6-bit hash of the x,y,z,w,u,v point with the given state
-
hash256_alt
-