赞
踩
xxHash是一个非常快的哈希算法,能在限制速度的RAM上运行。 它成功完成了SMHasher测试套件,它可以评估散列函数的冲突,色散和随机性。 代码非常便于携带,所有平台上的散列都相同(小/大)。测试对比参考:https://blog.csdn.net/tianshan2010/article/details/115775292
- public class XXHash {
-
- private static final int PRIME1 = (int) 2654435761L;
- private static final int PRIME2 = (int) 2246822519L;
- private static final int PRIME3 = (int) 3266489917L;
- private static final int PRIME4 = 668265263;
- private static final int PRIME5 = 0x165667b1;
-
- public static int digestSmall(byte[] data, int seed, boolean bigendian) {
-
- final EndianReader er = bigendian ? EncodeUtils.BEReader : EncodeUtils.LEReader;
- final int len = data.length;
- final int bEnd = len;
- final int limit = bEnd - 4;
-
- int idx = seed + PRIME1;
- int crc = PRIME5;
- int i = 0;
-
- while (i < limit) {
- crc += er.toInt(data, i) + (idx++);
- crc += Integer.rotateLeft(crc, 17) * PRIME4;
- crc *= PRIME1;
- i += 4;
- }
-
- while (i < bEnd) {
- crc += (data[i] & 0xFF) + (idx++);
- crc *= PRIME1;
- i++;
- }
-
- crc += len;
-
- crc ^= crc >>> 15;
- crc *= PRIME2;
- crc ^= crc >>> 13;
- crc *= PRIME3;
- crc ^= crc >>> 16;
-
- return crc;
-
- }
-
- public static int digestFast32(byte[] data, int seed, boolean bigendian) {
-
- final int len = data.length;
-
- if (len < 16) {
- return digestSmall(data, seed, bigendian);
- }
-
- final EndianReader er = bigendian ? EncodeUtils.BEReader : EncodeUtils.LEReader;
- final int bEnd = len;
- final int limit = bEnd - 16;
- int v1 = seed + PRIME1;
- int v2 &
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。