com.metamatrix.core.util
Class HashCodeUtil

java.lang.Object
  extended by com.metamatrix.core.util.HashCodeUtil

public final class HashCodeUtil
extends java.lang.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 Summary
HashCodeUtil()
           
 
Method Summary
static int expHashCode(int previous, java.util.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, ...
static int expHashCode(int previous, java.util.List x)
          Compute a hash code on a large list by walking the list and combining the hash code at every exponential index: 1, 2, 4, 8, ...
static int expHashCode(int previous, java.lang.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, ...
static int hashCode(int previous, boolean x)
           
static int hashCode(int previous, double x)
           
static int hashCode(int previous, float x)
           
static int hashCode(int previous, int x)
           
static int hashCode(int previous, long x)
           
static int hashCode(int previous, java.lang.Object x)
           
static int hashCode(int previous, java.lang.Object[] x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                                 java.lang.Object x)

hashCode

public static final int hashCode(int previous,
                                 java.lang.Object[] x)

expHashCode

public static final int expHashCode(int previous,
                                    java.lang.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,
                                    java.util.List x)
Compute a hash code on a large list 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,
                                    java.util.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. This uses an iterator to walk the collection and pull the necessary hash code values. Slower than a List or array but faster than getting EVERY value.



Copyright © 2009. All Rights Reserved.