public class CrossHash
extends java.lang.Object
hash64(int[])
, delegate to the CrossHash.Water
algorithm. This is a fairly fast and heavily-tested hash that developed from something like
Wang Yi's wyhash algorithm, though only the constants and the general concept of a mum()
function are shared with wyhash. There are several static inner classes in CrossHash
CrossHash.Water
(already mentioned), CrossHash.Yolk
(which is very close to Water but allows a
64-bit salt or seed), CrossHash.Curlup
(which is the fastest hash here for larger inputs, and
also allows a 64-bit seed), CrossHash.Mist
(which allows a 128-bit salt, but has mediocre
quality), CrossHash.Hive
(which is mostly here for compatibility, but has OK quality and good
collision rates), and CrossHash.Wisp
(which is fast for small inputs but has bad collision
rates). There's also the inner IHasher interface, and the classes that implement it.
Water, Yolk, and Curlup all pass the rigorous SMHasher test battery. The others don't pass
it in full, or sometimes at all.
Hashers
class for additional functions.
Modifier and Type | Class and Description |
---|---|
static class |
CrossHash.Curlup
Like Yolk, this is a class for hash functors, each an object with a 64-bit long seed.
|
static class |
CrossHash.Hive
A reasonably-fast hashing function that passes some of SMHasher's quality tests, but neither critically fails nor
overwhelmingly succeeds the full SMHasher test battery.
|
static interface |
CrossHash.IHasher
An interface that can be used to move the logic for the hashCode() and equals() methods from a class' methods to
an implementation of IHasher that certain collections in SquidLib can use.
|
static class |
CrossHash.Lightning
A quick, simple hashing function that seems to have good results.
|
static class |
CrossHash.Mist
A whole cluster of Wisp-like hash functions that sacrifice a small degree of speed, but can be built with up
to 128 bits of salt values that help to obscure what hashing function is actually being used.
|
static class |
CrossHash.Water
A fairly fast hashing algorithm in general, Water performs especially well on large arrays, and passes SMHasher's
newest and most stringent version of tests.
|
static class |
CrossHash.Wisp
The fastest hash in CrossHash, with middling quality.
|
static class |
CrossHash.Yolk
Like Mist, this is a class for hash functors, each an object with a 64-bit long seed, but it uses about the same
algorithm as
CrossHash.Water instead of the older, less-robust style Mist uses. |
Modifier and Type | Field and Description |
---|---|
static CrossHash.IHasher |
booleanHasher |
static CrossHash.IHasher |
byteHasher |
static CrossHash.IHasher |
char2DHasher |
static CrossHash.IHasher |
charHasher |
static CrossHash.IHasher |
defaultHasher |
static CrossHash.IHasher |
doubleHasher |
static CrossHash.IHasher |
floatHasher |
static CrossHash.IHasher |
generalHasher
This IHasher is the one you should use if you aren't totally certain what types will go in an OrderedMap's keys
or an OrderedSet's items, since it can handle mixes of elements.
|
static CrossHash.IHasher |
identityHasher |
static CrossHash.IHasher |
int2DHasher |
static CrossHash.IHasher |
intHasher |
static CrossHash.IHasher |
long2DHasher |
static CrossHash.IHasher |
longHasher |
static CrossHash.IHasher |
mildHasher
The most basic IHasher type; effectively delegates to
Objects.hashCode(Object) and
Objects.equals(Object, Object) . |
static CrossHash.IHasher |
objectArrayHasher |
static CrossHash.IHasher |
shortHasher |
static CrossHash.IHasher |
stringArrayHasher
Though the name suggests this only hashes String arrays, it can actually hash any CharSequence array as well.
|
static CrossHash.IHasher |
stringHasher |
Constructor and Description |
---|
CrossHash() |
Modifier and Type | Method and Description |
---|---|
static boolean |
equalityHelper(java.lang.Object[] left,
java.lang.Object[] right,
CrossHash.IHasher inner)
Not a general-purpose method; meant to ease implementation of
CrossHash.IHasher.areEqual(Object, Object)
methods when the type being compared is a multi-dimensional array (which normally requires the heavyweight method
Arrays.deepEquals(Object[], Object[]) or doing more work yourself; this reduces the work needed to
implement fixed-depth equality). |
static int |
hash(boolean[] data) |
static int |
hash(byte[] data) |
static int |
hash(char[] data) |
static int |
hash(char[][] data) |
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).
|
static int |
hash(java.lang.CharSequence data) |
static int |
hash(java.lang.CharSequence[]... data) |
static int |
hash(java.lang.CharSequence[] data) |
static int |
hash(java.lang.CharSequence data,
int start,
int end)
Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).
|
static int |
hash(double[] data) |
static int |
hash(float[] data) |
static int |
hash(int[] data) |
static int |
hash(int[][] data) |
static int |
hash(java.lang.Iterable<? extends java.lang.CharSequence> data) |
static int |
hash(java.util.List<? extends java.lang.CharSequence> data) |
static int |
hash(long[] data) |
static int |
hash(long[][] data) |
static int |
hash(java.lang.Object data) |
static int |
hash(java.lang.Object[] data) |
static int |
hash(short[] data) |
static long |
hash64(boolean[] data) |
static long |
hash64(byte[] data) |
static long |
hash64(char[] data) |
static long |
hash64(char[][] data) |
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).
|
static long |
hash64(java.lang.CharSequence data) |
static long |
hash64(java.lang.CharSequence[]... data) |
static long |
hash64(java.lang.CharSequence[] data) |
static long |
hash64(java.lang.CharSequence data,
int start,
int end)
Hashes only a subsection of the given data, starting at start (inclusive) and ending before end (exclusive).
|
static long |
hash64(double[] data) |
static long |
hash64(float[] data) |
static long |
hash64(int[] data) |
static long |
hash64(int[][] data) |
static long |
hash64(java.lang.Iterable<? extends java.lang.CharSequence> data) |
static long |
hash64(java.util.List<? extends java.lang.CharSequence> data) |
static long |
hash64(long[] data) |
static long |
hash64(long[][] data) |
static long |
hash64(java.lang.Object data) |
static long |
hash64(java.lang.Object[] data) |
static long |
hash64(short[] data) |
public static final CrossHash.IHasher booleanHasher
public static final CrossHash.IHasher byteHasher
public static final CrossHash.IHasher shortHasher
public static final CrossHash.IHasher charHasher
public static final CrossHash.IHasher intHasher
public static final CrossHash.IHasher longHasher
public static final CrossHash.IHasher floatHasher
public static final CrossHash.IHasher doubleHasher
public static final CrossHash.IHasher char2DHasher
public static final CrossHash.IHasher int2DHasher
public static final CrossHash.IHasher long2DHasher
public static final CrossHash.IHasher stringHasher
public static final CrossHash.IHasher stringArrayHasher
public static final CrossHash.IHasher objectArrayHasher
public static final CrossHash.IHasher defaultHasher
public static final CrossHash.IHasher mildHasher
Objects.hashCode(Object)
and
Objects.equals(Object, Object)
. Might not scramble the bits of a hash well enough to have good
performance in a hash table lke OrderedMap
or UnorderedSet
, unless the objects being hashed have
good hashCode() implementations already.public static final CrossHash.IHasher identityHasher
public static final CrossHash.IHasher generalHasher
public static long hash64(java.lang.CharSequence data)
public static long hash64(boolean[] data)
public static long hash64(byte[] data)
public static long hash64(short[] data)
public static long hash64(int[] data)
public static long hash64(long[] data)
public static long hash64(char[] data)
public static long hash64(float[] data)
public static long hash64(double[] data)
public static long hash64(char[] data, int start, int end)
data
- the char array to hashstart
- the start of the section to hash (inclusive)end
- the end of the section to hash (exclusive)public static long hash64(java.lang.CharSequence data, int start, int end)
data
- the String or other CharSequence to hashstart
- the start of the section to hash (inclusive)end
- the end of the section to hash (exclusive)public static long hash64(char[][] data)
public static long hash64(int[][] data)
public static long hash64(long[][] data)
public static long hash64(java.lang.CharSequence[] data)
public static long hash64(java.lang.CharSequence[]... data)
public static long hash64(java.lang.Iterable<? extends java.lang.CharSequence> data)
public static long hash64(java.util.List<? extends java.lang.CharSequence> data)
public static long hash64(java.lang.Object[] data)
public static long hash64(java.lang.Object data)
public static int hash(java.lang.CharSequence data)
public static int hash(boolean[] data)
public static int hash(byte[] data)
public static int hash(short[] data)
public static int hash(int[] data)
public static int hash(long[] data)
public static int hash(char[] data)
public static int hash(float[] data)
public static int hash(double[] data)
public static int hash(char[] data, int start, int end)
data
- the char array to hashstart
- the start of the section to hash (inclusive)end
- the end of the section to hash (exclusive)public static int hash(java.lang.CharSequence data, int start, int end)
data
- the String or other CharSequence to hashstart
- the start of the section to hash (inclusive)end
- the end of the section to hash (exclusive)public static int hash(char[][] data)
public static int hash(int[][] data)
public static int hash(long[][] data)
public static int hash(java.lang.CharSequence[] data)
public static int hash(java.lang.CharSequence[]... data)
public static int hash(java.lang.Iterable<? extends java.lang.CharSequence> data)
public static int hash(java.util.List<? extends java.lang.CharSequence> data)
public static int hash(java.lang.Object[] data)
public static int hash(java.lang.Object data)
public static boolean equalityHelper(java.lang.Object[] left, java.lang.Object[] right, CrossHash.IHasher inner)
CrossHash.IHasher.areEqual(Object, Object)
methods when the type being compared is a multi-dimensional array (which normally requires the heavyweight method
Arrays.deepEquals(Object[], Object[])
or doing more work yourself; this reduces the work needed to
implement fixed-depth equality). As mentioned in the docs for CrossHash.IHasher.areEqual(Object, Object)
, example
code that hashes 2D char arrays can be done using an IHasher for 1D char arrays called charHasher:
return left == right
|| ((left instanceof char[][] && right instanceof char[][])
? equalityHelper((char[][]) left, (char[][]) right, charHasher)
: Objects.equals(left, right));
left
- an array of some kind of Object, usually an array, that the given IHasher can compareright
- an array of some kind of Object, usually an array, that the given IHasher can compareinner
- an IHasher to compare items in left with items in rightCopyright © Eben Howard 2012–2022. All rights reserved.