public static interface CrossHash.IHasher
extends java.io.Serializable
Hashers
for additional implementations, some of which need dependencies on
things the rest of CrossHash doesn't, like a case-insensitive String hasher/equator that uses RegExodus to handle
CharSequence comparison on GWT.Modifier and Type | Method and Description |
---|---|
boolean |
areEqual(java.lang.Object left,
java.lang.Object right)
Not all types you might want to use an IHasher on meaningfully implement .equals(), such as array types; in
these situations the areEqual method helps quickly check for equality by potentially having special logic for
the type this is meant to check.
|
int |
hash(java.lang.Object data)
If data is a type that this IHasher can specifically hash, this method should use that specific hash; in
other situations, it should simply delegate to calling
Object.hashCode() on data. |
int hash(java.lang.Object data)
Object.hashCode()
on data. The body of an
implementation of this method can be very small; for an IHasher that is meant for byte arrays, the body could
be: return (data instanceof byte[]) ? CrossHash.Lightning.hash((byte[]) data) : data.hashCode();
data
- the Object to hash; this method should take any type but often has special behavior for one typeboolean areEqual(java.lang.Object left, java.lang.Object right)
return left == right
|| ((left instanceof byte[] && right instanceof byte[])
? Arrays.equals((byte[]) left, (byte[]) right)
: Objects.equals(left, right));
, but for multidimensional arrays you should use the
CrossHash.equalityHelper(Object[], Object[], IHasher)
method with an IHasher for the inner arrays that are 1D
or otherwise already-hash-able, as can be seen in the body of the implementation for 2D char arrays, where
charHasher is an existing IHasher that handles 1D arrays:
return left == right
|| ((left instanceof char[][] && right instanceof char[][])
? equalityHelper((char[][]) left, (char[][]) right, charHasher)
: Objects.equals(left, right));
left
- allowed to be null; most implementations will have special behavior for one typeright
- allowed to be null; most implementations will have special behavior for one typeCopyright © Eben Howard 2012–2022. All rights reserved.