[infinispan-commits] Infinispan SVN: r944 - trunk/core/src/main/java/org/infinispan/container.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Oct 14 09:04:50 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-10-14 09:04:50 -0400 (Wed, 14 Oct 2009)
New Revision: 944

Modified:
   trunk/core/src/main/java/org/infinispan/container/FIFODataContainer.java
Log:
Better bit spreader

Modified: trunk/core/src/main/java/org/infinispan/container/FIFODataContainer.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/container/FIFODataContainer.java	2009-10-14 11:24:44 UTC (rev 943)
+++ trunk/core/src/main/java/org/infinispan/container/FIFODataContainer.java	2009-10-14 13:04:50 UTC (rev 944)
@@ -357,7 +357,7 @@
     * defends against poor quality hash functions.  This is critical because ConcurrentHashMap uses power-of-two length
     * hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits.
     */
-   final int hash(int h) {
+   final int hashOld(int h) {
       // Spread bits to regularize both segment and index locations,
       // using variant of single-word Wang/Jenkins hash.
       h += (h << 15) ^ 0xffffcd7d;
@@ -369,6 +369,25 @@
    }
 
    /**
+    * Use the objects built in hash to obtain an initial value, then use a second four byte hash to obtain a more
+    * uniform distribution of hash values. This uses a <a href = "http://burtleburtle.net/bob/hash/integer.html">4-byte
+    * (integer) hash</a>, which produces well distributed values even when the original hash produces thghtly clustered
+    * values.
+    * <p />
+    * Contributed by akluge <a href-="http://www.vizitsolutions.com/ConsistentHashingCaching.html">http://www.vizitsolutions.com/ConsistentHashingCaching.html</a>
+    */
+   final int hash(int hash) {
+      hash = (hash + 0x7ED55D16) + (hash << 12);
+      hash = (hash ^ 0xc761c23c) ^ (hash >> 19);
+      hash = (hash + 0x165667b1) + (hash << 5);
+      hash = (hash + 0xd3a2646c) ^ (hash << 9);
+      hash = (hash + 0xfd7046c5) + (hash << 3);
+      hash = (hash ^ 0xb55a4f09) ^ (hash >> 16);
+
+      return hash;
+   }
+
+   /**
     * Returns the segment that should be used for key with given hash
     *
     * @param hash the hash code for the key



More information about the infinispan-commits mailing list