1、RSHash算法
public static int RSHash(byte[] bytes) {
int hash = 0;
int magic = 63689;
for (byte b : bytes) {
hash = hash * magic + b;
magic = magic * 378551;
}
return hash;
}
2、JSHash算法
public static int JSHash(byte[] bytes) {
int hash = 1315423911;
for (byte b : bytes) {
hash ^= ((hash << 5) + b + (hash >> 2));
}
return hash;
}
3、ELFHash算法
public static int ELFHash(byte[] bytes) {
int hash = 0;
int x;
for (byte b : bytes) {
hash = (hash << 4) + b;
if ((x = hash & 0xF0000000) != 0) {
hash ^= (x >> 24);
hash &= ~x;
}
}
return hash;
}
4、BKDRHash算法
public static int BKDRHash(byte[] bytes) {
int seed = 131;
int hash = 0;
for (byte b : bytes) {
hash = (hash * seed) + b;
}
return hash;
}
5、BKDRHash算法
public static int c(byte[] bytes) {
int hash = 0;
int len = bytes.length;
for (int i = 0; i < len; i++) {
if ((i & 1) == 0) {
hash ^= ((hash << 7) ^ bytes[i] ^ (hash >> 3));
} else {
hash ^= (~((hash << 11) ^ bytes[i] ^ (hash >> 5)));
}
}
return hash;
}
6、DJBHash算法
public static int DJBHash(byte[] bytes) {
int hash = 5381;
for (byte b : bytes) {
hash = ((hash << 5) + hash) + b;
}
return hash;
}
7、SDBMHash算法
public static int SDBMHash(byte[] bytes) {
int hash = 0;
for (byte b : bytes) {
hash = b + (hash << 6) + (hash << 16) - hash;
}
return hash;
}
8、PJWHash算法
public static int PJWHash(byte[] bytes) {
long bitsInUnsignedInt = (4 << 3);
long threeQuarters = ((bitsInUnsignedInt * 3) >> 2);
long oneEighth = (bitsInUnsignedInt >> 3);
long highBits = (long) (0xFFFFFFFF) << (bitsInUnsignedInt - oneEighth);
int hash = 0;
long test;
for (byte b : bytes) {
hash = (hash << oneEighth) + b;
if ((test = hash & highBits) != 0) {
hash = (int) ((hash ^ (test >> threeQuarters)) & (~highBits));
}
}
return hash;
}