aboutsummaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/collect/Hashing.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava/src/com/google/common/collect/Hashing.java')
-rw-r--r--guava/src/com/google/common/collect/Hashing.java39
1 files changed, 8 insertions, 31 deletions
diff --git a/guava/src/com/google/common/collect/Hashing.java b/guava/src/com/google/common/collect/Hashing.java
index b13eb7c..9c5f6bc 100644
--- a/guava/src/com/google/common/collect/Hashing.java
+++ b/guava/src/com/google/common/collect/Hashing.java
@@ -17,50 +17,27 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.primitives.Ints;
/**
* Static methods for implementing hash-based collections.
*
* @author Kevin Bourrillion
* @author Jesse Wilson
- * @author Austin Appleby
*/
@GwtCompatible
final class Hashing {
private Hashing() {}
- private static final int C1 = 0xcc9e2d51;
- private static final int C2 = 0x1b873593;
-
/*
- * This method was rewritten in Java from an intermediate step of the Murmur hash function in
- * http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp, which contained the
- * following header:
- *
- * MurmurHash3 was written by Austin Appleby, and is placed in the public domain. The author
- * hereby disclaims copyright to this source code.
+ * This method was written by Doug Lea with assistance from members of JCP
+ * JSR-166 Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
+ *
+ * As of 2010/06/11, this method is identical to the (package private) hash
+ * method in OpenJDK 7's java.util.HashMap class.
*/
static int smear(int hashCode) {
- return C2 * Integer.rotateLeft(hashCode * C1, 15);
- }
-
- static int MAX_TABLE_SIZE = Ints.MAX_POWER_OF_TWO;
-
- static int closedTableSize(int expectedEntries, double loadFactor) {
- // Get the recommended table size.
- // Round down to the nearest power of 2.
- expectedEntries = Math.max(expectedEntries, 2);
- int tableSize = Integer.highestOneBit(expectedEntries);
- // Check to make sure that we will not exceed the maximum load factor.
- if ((double) expectedEntries / tableSize > loadFactor) {
- tableSize <<= 1;
- return (tableSize > 0) ? tableSize : MAX_TABLE_SIZE;
- }
- return tableSize;
- }
-
- static boolean needsResizing(int size, int tableSize, double loadFactor) {
- return size > loadFactor * tableSize && tableSize < MAX_TABLE_SIZE;
+ hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12);
+ return hashCode ^ (hashCode >>> 7) ^ (hashCode >>> 4);
}
}