Class CrossHash.Curlup

java.lang.Object
squidpony.squidmath.CrossHash.Curlup
Enclosing class:
CrossHash

public static final class CrossHash.Curlup
extends Object
Like Yolk, this is a class for hash functors, each an object with a 64-bit long seed. It uses an odd-but-fast SIMD-friendly technique when hashing 32-bit items or smaller, and falls back to Yolk's algorithm when hashing long values. If you are mainly hashing int arrays, short arrays, or byte arrays, this is probably the fastest hash here unless the arrays are small (it outperforms all of the other hashes here on int arrays when those arrays have length 50, and probably is faster than some sooner than that). Notably, on arrays 50 or longer this runs in very close to half the time of Arrays.hashCode(int[]). This passes SMHasher for at least 64-bit output. Has a lot of predefined functors (192, named after 24 Greek letters and 72 Goetic demons, see Wikipedia for the demons, in both lower case and lower case with a trailing underscore). You probably want to use predefined instead of wrangling demon names; you can always choose an element from predefined with a 7-bit number, and there are 64 numbers outside that range so you can choose any of those when a functor must be different.
This hash is much more effective with large inputs because it takes advantage of HotSpot's optimizations for code that looks like a dot product over part of an array. The general concept for this hash came from the "Unrolled" hash in one of Richard Startin's blog posts, which traces back to Peter Levart posting a related improvement on String.hashCode() in 2014. This isn't as fast as Startin's "Vectorized" hash, but this works on variable array lengths and also passes SMHasher.
The name curlup comes from an M.C. Escher painting of a creature, whose name translates to curl-up, that could walk on six legs to climb stairs, or roll at high speeds when the conditions were right.