提交 4f2cb320 authored 作者: Thomas Mueller's avatar Thomas Mueller

Faster hash code calculation for large binary arrays.

上级 afa6e52d
......@@ -107,9 +107,21 @@ public class ByteUtils {
* @return the hash code
*/
public static int getByteArrayHash(byte[] value) {
int h = 1;
for (int i = 0; i < value.length;) {
h = 31 * h + value[i++];
int len = value.length;
int h = len;
if (len < 50) {
for (int i = 0; i < len; i++) {
h = 31 * h + value[i];
}
} else {
int step = len / 16;
for (int i = 0; i < 4; i++) {
h = 31 * h + value[i];
h = 31 * h + value[--len];
}
for (int i = 4 + step; i < len; i += step) {
h = 31 * h + value[i];
}
}
return h;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论