Class HashCodeUtil


  • public final class HashCodeUtil
    extends Object

    This class provides utility functions for generating good hash codes. Hash codes generated with these methods should have a reasonably good distribution when placed in a hash structure such as Hashtable, HashSet, or HashMap.

    General usage is something like:

     public int hashCode() {
         int hc = 0;    // or = super.hashCode();
         hc = HashCodeUtil.hashCode(hc, intField);
         hc = HashCodeUtil.hashCode(hc, objectField);
         // etc, etc
         return hc;
     }
     
    • Constructor Detail

      • HashCodeUtil

        public HashCodeUtil()
    • Method Detail

      • hashCode

        public static final int hashCode​(int previous,
                                         boolean x)
      • hashCode

        public static final int hashCode​(int previous,
                                         int x)
      • hashCode

        public static final int hashCode​(int previous,
                                         long x)
      • hashCode

        public static final int hashCode​(int previous,
                                         float x)
      • hashCode

        public static final int hashCode​(int previous,
                                         double x)
      • hashCode

        public static final int hashCode​(int previous,
                                         Object... x)
      • expHashCode

        public static final int expHashCode​(int previous,
                                            Object[] x)
        Compute a hash code on a large array by walking the list and combining the hash code at every exponential index: 1, 2, 4, 8, ... This has been shown to give a good hash for good time complexity.
      • expHashCode

        public static final int expHashCode​(int previous,
                                            Collection<?> x)
        Compute a hash code on a large collection by walking the list and combining the hash code at every exponential index: 1, 2, 4, 8, ... This has been shown to give a good hash for good time complexity.
      • expHashCode

        public static final int expHashCode​(CharSequence x)
      • expHashCode

        public static final int expHashCode​(CharSequence x,
                                            boolean caseSensitive)