Class CrossHash.Curlup

java.lang.Object
com.github.yellowstonegames.old.v300.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.
  • Field Details

  • Constructor Details

    • Curlup

      public Curlup()
    • Curlup

      public Curlup(long seed)
    • Curlup

      public Curlup(CharSequence seed)
  • Method Details

    • randomize

      public static long randomize(long seed)
      Very similar to Pelican and related unary hashes; uses "xor rotate xor rotate" as an early step to mix any clustered bits all around the result, then the rest is like MurmurHash3's mixer.
      Parameters:
      seed - any long; there is no fix point at 0
      Returns:
      any long
    • hash64

      public long hash64(boolean[] data)
    • hash64

      public long hash64(byte[] data)
    • hash64

      public long hash64(short[] data)
    • hash64

      public long hash64(char[] data)
    • hash64

      public long hash64(CharSequence data)
    • hash64

      public long hash64(int[] data)
    • hash64

      public long hash64(int[] data, int length)
    • hash64

      public long hash64(long[] data)
    • hash64

      public long hash64(float[] data)
    • hash64

      public long hash64(double[] data)
    • hash64

      public 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 hash
      start - 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 long hash64(CharSequence 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 String or other CharSequence to hash
      start - 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 long hash64(char[][] data)
    • hash64

      public long hash64(int[][] data)
    • hash64

      public long hash64(long[][] data)
    • hash64

      public long hash64(CharSequence[] data)
    • hash64

      public long hash64(CharSequence[]... data)
    • hash64

      public long hash64(Iterable<? extends CharSequence> data)
    • hash64

      public long hash64(List<? extends CharSequence> data)
    • hash64

      public long hash64(Object[] data)
    • hash64

      public long hash64(Object data)
    • hash

      public int hash(boolean[] data)
    • hash

      public int hash(byte[] data)
    • hash

      public int hash(short[] data)
    • hash

      public int hash(char[] data)
    • hash

      public int hash(CharSequence data)
    • hash

      public int hash(int[] data)
    • hash

      public int hash(int[] data, int length)
    • hash

      public int hash(long[] data)
    • hash

      public int hash(float[] data)
    • hash

      public int hash(double[] data)
    • hash

      public 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 hash
      start - 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
    • hash

      public int hash(CharSequence 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 String or other CharSequence to hash
      start - 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
    • hash

      public int hash(char[][] data)
    • hash

      public int hash(int[][] data)
    • hash

      public int hash(long[][] data)
    • hash

      public int hash(CharSequence[] data)
    • hash

      public int hash(CharSequence[]... data)
    • hash

      public int hash(Iterable<? extends CharSequence> data)
    • hash

      public int hash(List<? extends CharSequence> data)
    • hash

      public int hash(Object[] data)
    • hash

      public int hash(Object data)
    • hash64

      public static long hash64(long seed, boolean[] data)
    • hash64

      public static long hash64(long seed, byte[] data)
    • hash64

      public static long hash64(long seed, short[] data)
    • hash64

      public static long hash64(long seed, char[] data)
    • hash64

      public static long hash64(long seed, CharSequence data)
    • hash64

      public static long hash64(long seed, int[] data)
    • hash64

      public static long hash64(long seed, int[] data, int length)
    • hash64

      public static long hash64(long seed, long[] data)
    • hash64

      public static long hash64(long seed, float[] data)
    • hash64

      public static long hash64(long seed, double[] data)
    • hash64

      public static long hash64(long seed, 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 hash
      start - 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(long seed, CharSequence 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 String or other CharSequence to hash
      start - 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(long seed, char[][] data)
    • hash64

      public static long hash64(long seed, int[][] data)
    • hash64

      public static long hash64(long seed, long[][] data)
    • hash64

      public static long hash64(long seed, CharSequence[] data)
    • hash64

      public static long hash64(long seed, CharSequence[]... data)
    • hash64

      public static long hash64(long seed, Iterable<? extends CharSequence> data)
    • hash64

      public static long hash64(long seed, List<? extends CharSequence> data)
    • hash64

      public static long hash64(long seed, Object[] data)
    • hash64

      public static long hash64(long seed, Object data)
    • hash

      public static int hash(long seed, boolean[] data)
    • hash

      public static int hash(long seed, byte[] data)
    • hash

      public static int hash(long seed, short[] data)
    • hash

      public static int hash(long seed, char[] data)
    • hash

      public static int hash(long seed, CharSequence data)
    • hash

      public static int hash(long seed, int[] data)
    • hash

      public static int hash(long seed, int[] data, int length)
    • hash

      public static int hash(long seed, long[] data)
    • hash

      public static int hash(long seed, float[] data)
    • hash

      public static int hash(long seed, double[] data)
    • hash

      public static int hash(long seed, 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 hash
      start - 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
    • hash

      public static int hash(long seed, CharSequence 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 String or other CharSequence to hash
      start - 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
    • hash

      public static int hash(long seed, char[][] data)
    • hash

      public static int hash(long seed, int[][] data)
    • hash

      public static int hash(long seed, long[][] data)
    • hash

      public static int hash(long seed, CharSequence[] data)
    • hash

      public static int hash(long seed, CharSequence[]... data)
    • hash

      public static int hash(long seed, Iterable<? extends CharSequence> data)
    • hash

      public static int hash(long seed, List<? extends CharSequence> data)
    • hash

      public static int hash(long seed, Object[] data)
    • hash

      public static int hash(long seed, Object data)