Class CrossHash.Wisp

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

public static final class CrossHash.Wisp
extends Object
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 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. Because the hash-based collections in SquidLib need a pretty good hash function to work at their best (they use linear-probing with open addressing, which struggles when hashes are bad), 20% loss of speed during hashing to avoid slower lookups/insertions/deletions from OrderedMap, OrderedSet, UnorderedMap, UnorderedSet, Arrangement, and others is probably worth it; if you really need speed then you should first consider CrossHash.Curlup, which is faster than Wisp on moderately-long input arrays (with 20 or more items, usually), and only if you need a fast hash for small inputs, where collisions aren't a problem, should you turn to Wisp.
  • Constructor Summary

    Constructors 
    Constructor Description
    Wisp()  
  • Method Summary

    Modifier and Type Method Description
    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​(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 int hash​(double[] data)  
    static int hash​(float[] data)  
    static int hash​(int[] data)  
    static int hash​(int[][] data)  
    static int hash​(long[] data)  
    static int hash​(long[][] data)  
    static int hash​(short[] data)  
    static int hash​(CharSequence data)  
    static int hash​(CharSequence[] data)  
    static int hash​(CharSequence[]... data)  
    static int hash​(Iterable<? extends CharSequence> data)  
    static int hash​(Object data)  
    static int hash​(Object[] data)  
    static int hash​(List<? extends CharSequence> data)  
    static int hash32​(boolean[] data)  
    static int hash32​(byte[] data)  
    static int hash32​(char[] data)  
    static int hash32​(char[][] data)  
    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).
    static int hash32​(double[] data)  
    static int hash32​(float[] data)  
    static int hash32​(int[] data)  
    static int hash32​(int[][] data)  
    static int hash32​(long[] data)  
    static int hash32​(long[][] data)  
    static int hash32​(short[] data)  
    static int hash32​(CharSequence data)  
    static int hash32​(CharSequence[] data)  
    static int hash32​(CharSequence[]... data)  
    static int hash32​(Iterable<? extends CharSequence> data)  
    static int hash32​(Object data)  
    static int hash32​(Object[] data)  
    static int hash32​(List<? extends CharSequence> 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​(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 long hash64​(double[] data)  
    static long hash64​(float[] data)  
    static long hash64​(int[] data)  
    static long hash64​(int[][] data)  
    static long hash64​(long[] data)  
    static long hash64​(long[][] data)  
    static long hash64​(short[] data)  
    static long hash64​(CharSequence data)  
    static long hash64​(CharSequence[] data)  
    static long hash64​(CharSequence[]... data)  
    static long hash64​(Iterable<? extends CharSequence> data)  
    static long hash64​(Object data)  
    static long hash64​(Object[] data)  
    static long hash64​(List<? extends CharSequence> data)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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

      public static long hash64​(CharSequence data)
    • 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 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​(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 hash
      start - 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

      public static long hash64​(CharSequence[] data)
    • hash64

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

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

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

      public static long hash64​(Object[] data)
    • hash64

      public static long hash64​(Object data)
    • 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

      public static int hash32​(CharSequence data)
    • 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 hash
      start - 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

      public static int hash32​(CharSequence[] data)
    • hash32

      public static int hash32​(CharSequence[]... data)
    • hash32

      public static int hash32​(Iterable<? extends CharSequence> data)
    • hash32

      public static int hash32​(List<? extends CharSequence> data)
    • hash32

      public static int hash32​(Object[] data)
    • hash32

      public static int hash32​(Object data)
    • 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

      public static int hash​(CharSequence data)
    • 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 hash
      start - 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 hash
      start - 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

      public static int hash​(CharSequence[] data)
    • hash

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

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

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

      public static int hash​(Object[] data)
    • hash

      public static int hash​(Object data)