Class CrossHash.Wisp
java.lang.Object
com.github.yellowstonegames.old.v300.CrossHash.Wisp
- Enclosing class:
CrossHash
The fastest hash in CrossHash, with middling quality. Uses a finely-tuned mix of very few operations for each
element, plus a minimal and simple finalization step, and as such obtains superior speed on the standard
benchmark SquidLib uses for hashes (hashing one million 16-element long arrays, remaining the best in both 32-bit
and 64-bit versions). Specifically, Wisp takes 9.478 ms to generate a million 64-bit hashes on a recent laptop
with an i7-6700HQ processor (removing the time the control takes to generate the million arrays). For comparison,
the JDK's Arrays.hashCode method takes 13.642 ms on the same workload, though it produces 32-bit hashes. Wisp
performs almost exactly as well producing 32-bit hashes as it does 64-bit hashes, where Hive slows down
significantly on some input types. This also passes visual tests where an earlier version of Wisp did not.
Collision rates are slightly worse than other CrossHash classes, but are better than the JDK's
Arrays.hashCode method, that is, acceptably low when given varied-enough inputs. On certain kinds of similar
inputs, Wisp will struggle with a higher collision rate. For example, when hashing Strings that contain only
several spaces, then some combination of digits 0-5, then more spaces, Wisp does very badly, worse than
This version replaces an older version of Wisp that had serious quality issues and wasn't quite as fast. Since the only reason one would use the older version was speed without regard for quality, and it was marked as Beta, a faster version makes sense to replace the slower one, rather than add yet another nested class in CrossHash.
Wisp is no longer considered Beta-quality, but even though it is rather fast, it has some cases where categories of input cause frequent collisions.
String.hashCode() (which also does badly, though not as badly), while other hashes here do fine (such as
Water, which is the default for CrossHash.hash(CharSequence)).
This version replaces an older version of Wisp that had serious quality issues and wasn't quite as fast. Since the only reason one would use the older version was speed without regard for quality, and it was marked as Beta, a faster version makes sense to replace the slower one, rather than add yet another nested class in CrossHash.
Wisp is no longer considered Beta-quality, but even though it is rather fast, it has some cases where categories of input cause frequent collisions.
CrossHash.Water is about 20% slower but doesn't have such categories of
pathologically bad inputs, and passes tests that Wisp fails badly on.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic inthash(boolean[] data) static inthash(byte[] data) static inthash(char[] data) static inthash(char[][] data) static inthash(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).static inthash(char[] data, int start, int end, int step) Hashes only a subsection of the given data, starting at start (inclusive), ending before end (exclusive), and moving between chars in increments of step (which is always greater than 0).static inthash(double[] data) static inthash(float[] data) static inthash(int[] data) static inthash(int[][] data) static inthash(long[] data) static inthash(long[][] data) static inthash(short[] data) static inthash(CharSequence data) static inthash(CharSequence[] data) static inthash(CharSequence[]... data) static inthash(Iterable<? extends CharSequence> data) static intstatic intstatic inthash(List<? extends CharSequence> data) static inthash32(boolean[] data) static inthash32(byte[] data) static inthash32(char[] data) static inthash32(char[][] data) static inthash32(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).static inthash32(double[] data) static inthash32(float[] data) static inthash32(int[] data) static inthash32(int[][] data) static inthash32(long[] data) static inthash32(long[][] data) static inthash32(short[] data) static inthash32(CharSequence data) static inthash32(CharSequence[] data) static inthash32(CharSequence[]... data) static inthash32(Iterable<? extends CharSequence> data) static intstatic intstatic inthash32(List<? extends CharSequence> data) static longhash64(boolean[] data) static longhash64(byte[] data) static longhash64(char[] data) static longhash64(char[][] data) static longhash64(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).static longhash64(char[] data, int start, int end, int step) Hashes only a subsection of the given data, starting at start (inclusive), ending before end (exclusive), and moving between chars in increments of step (which is always greater than 0).static longhash64(double[] data) static longhash64(float[] data) static longhash64(int[] data) static longhash64(int[][] data) static longhash64(long[] data) static longhash64(long[][] data) static longhash64(short[] data) static longhash64(CharSequence data) static longhash64(CharSequence[] data) static longhash64(CharSequence[]... data) static longhash64(Iterable<? extends CharSequence> data) static longstatic longstatic longhash64(List<? extends CharSequence> data)
-
Constructor Details
-
Wisp
public Wisp()
-
-
Method Details
-
hash64
public static long hash64(boolean[] data) -
hash64
public static long hash64(byte[] data) -
hash64
public static long hash64(short[] data) -
hash64
public static long hash64(char[] data) -
hash64
public static long hash64(int[] data) -
hash64
public static long hash64(long[] data) -
hash64
public static long hash64(float[] data) -
hash64
public static long hash64(double[] data) -
hash64
-
hash64
public static long hash64(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).- Parameters:
data- the char array to hashstart- the start of the section to hash (inclusive)end- the end of the section to hash (exclusive)- Returns:
- a 64-bit hash code for the requested section of data
-
hash64
public static long hash64(char[] data, int start, int end, int step) Hashes only a subsection of the given data, starting at start (inclusive), ending before end (exclusive), and moving between chars in increments of step (which is always greater than 0).- Parameters:
data- the char array to hashstart- the start of the section to hash (inclusive)end- the end of the section to hash (exclusive)step- how many elements to advance after using one element from data; must be greater than 0- Returns:
- a 64-bit hash code for the requested section of data
-
hash64
public static long hash64(char[][] data) -
hash64
public static long hash64(int[][] data) -
hash64
public static long hash64(long[][] data) -
hash64
-
hash64
-
hash64
-
hash64
-
hash64
-
hash64
-
hash32
public static int hash32(boolean[] data) -
hash32
public static int hash32(byte[] data) -
hash32
public static int hash32(short[] data) -
hash32
public static int hash32(char[] data) -
hash32
public static int hash32(int[] data) -
hash32
public static int hash32(long[] data) -
hash32
public static int hash32(float[] data) -
hash32
public static int hash32(double[] data) -
hash32
-
hash32
public static int hash32(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive). Uses 32-bit math on most platforms, but will give different results on GWT due to it using double values that only somewhat act like int values.- Parameters:
data- the char array to hashstart- the start of the section to hash (inclusive)end- the end of the section to hash (exclusive)- Returns:
- a 32-bit hash code for the requested section of data
-
hash32
public static int hash32(char[][] data) -
hash32
public static int hash32(int[][] data) -
hash32
public static int hash32(long[][] data) -
hash32
-
hash32
-
hash32
-
hash32
-
hash32
-
hash32
-
hash
public static int hash(boolean[] data) -
hash
public static int hash(byte[] data) -
hash
public static int hash(short[] data) -
hash
public static int hash(char[] data) -
hash
public static int hash(int[] data) -
hash
public static int hash(long[] data) -
hash
public static int hash(float[] data) -
hash
public static int hash(double[] data) -
hash
-
hash
public static int hash(char[] data, int start, int end) Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).- Parameters:
data- the char array to hashstart- the start of the section to hash (inclusive)end- the end of the section to hash (exclusive)- Returns:
- a 32-bit hash code for the requested section of data
-
hash
public static int hash(char[] data, int start, int end, int step) Hashes only a subsection of the given data, starting at start (inclusive), ending before end (exclusive), and moving between chars in increments of step (which is always greater than 0).- Parameters:
data- the char array to hashstart- the start of the section to hash (inclusive)end- the end of the section to hash (exclusive)step- how many elements to advance after using one element from data; must be greater than 0- Returns:
- a 32-bit hash code for the requested section of data
-
hash
public static int hash(char[][] data) -
hash
public static int hash(int[][] data) -
hash
public static int hash(long[][] data) -
hash
-
hash
-
hash
-
hash
-
hash
-
hash
-