Changed MurmurHash algo, to the one developed in http://github.com/tdunning/MAHOUT-228
This commit is contained in:
@@ -3,55 +3,9 @@ package redis.clients.util;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public abstract class Hashing {
|
||||
public static final Hashing MURMURE_HASH = new Hashing() {
|
||||
public long hash(String key) {
|
||||
// 'm' and 'r' are mixing constants generated offline.
|
||||
// They're not really 'magic', they just happen to work well.
|
||||
byte[] data = key.getBytes();
|
||||
int seed = 0x1234ABCD;
|
||||
int m = 0x5bd1e995;
|
||||
int r = 24;
|
||||
public interface Hashing {
|
||||
public static final Hashing MURMUR_HASH = new MurmurHash();
|
||||
|
||||
// Initialize the hash to a 'random' value
|
||||
int len = data.length;
|
||||
int h = seed ^ len;
|
||||
|
||||
int i = 0;
|
||||
while (len >= 4) {
|
||||
int k = data[i + 0] & 0xFF;
|
||||
k |= (data[i + 1] & 0xFF) << 8;
|
||||
k |= (data[i + 2] & 0xFF) << 16;
|
||||
k |= (data[i + 3] & 0xFF) << 24;
|
||||
|
||||
k *= m;
|
||||
k ^= k >>> r;
|
||||
k *= m;
|
||||
|
||||
h *= m;
|
||||
h ^= k;
|
||||
|
||||
i += 4;
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
switch (len) {
|
||||
case 3:
|
||||
h ^= (data[i + 2] & 0xFF) << 16;
|
||||
case 2:
|
||||
h ^= (data[i + 1] & 0xFF) << 8;
|
||||
case 1:
|
||||
h ^= (data[i + 0] & 0xFF);
|
||||
h *= m;
|
||||
}
|
||||
|
||||
h ^= h >>> 13;
|
||||
h *= m;
|
||||
h ^= h >>> 15;
|
||||
|
||||
return h;
|
||||
}
|
||||
};
|
||||
public static final Hashing MD5 = new Hashing() {
|
||||
private MessageDigest md5 = null; // avoid recurring construction
|
||||
|
||||
@@ -75,5 +29,5 @@ public abstract class Hashing {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract long hash(String key);
|
||||
public long hash(String key);
|
||||
}
|
||||
Reference in New Issue
Block a user