Binary key & values seems to be implemented now

This commit is contained in:
Yaourt
2010-11-04 15:59:50 +01:00
parent 84bb16dd5e
commit e2d8148802
8 changed files with 417 additions and 35 deletions

View File

@@ -3,13 +3,19 @@ package redis.clients.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import redis.clients.jedis.Protocol;
public interface Hashing {
public static final Hashing MURMUR_HASH = new MurmurHash();
public static final Hashing MD5 = new Hashing() {
private MessageDigest md5 = null; // avoid recurring construction
public long hash(String key) {
return hash(key.getBytes(Protocol.UTF8));
}
public long hash(byte[] key) {
if (md5 == null) {
try {
md5 = MessageDigest.getInstance("MD5");
@@ -20,7 +26,7 @@ public interface Hashing {
}
md5.reset();
md5.update(key.getBytes());
md5.update(key);
byte[] bKey = md5.digest();
long res = ((long) (bKey[3] & 0xFF) << 24)
| ((long) (bKey[2] & 0xFF) << 16)
@@ -30,4 +36,5 @@ public interface Hashing {
};
public long hash(String key);
public long hash(byte[] key);
}