Skip to content

Commit cd176f9

Browse files
committed
fix hash
1 parent 37ade5b commit cd176f9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
### 新特性
99
* 【cache】 缓存增加get重载(pr#404@Github)
10-
* 【poi 】 增加WordUtil
10+
* 【poi】 增加WordUtil
11+
* 【core】 改进fnvHash避免负数(issue#IYDK6@Gitee)
1112

1213
### Bug修复
1314

hutool-core/src/main/java/cn/hutool/core/util/HashUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static int fnvHash(byte[] data) {
152152
hash += hash << 3;
153153
hash ^= hash >> 17;
154154
hash += hash << 5;
155-
return hash;
155+
return Math.abs(hash);
156156
}
157157

158158
/**
@@ -172,9 +172,9 @@ public static int fnvHash(String data) {
172172
hash += hash << 3;
173173
hash ^= hash >> 17;
174174
hash += hash << 5;
175-
return hash;
175+
return Math.abs(hash);
176176
}
177-
177+
178178
/**
179179
* Thomas Wang的算法,整数hash
180180
*

0 commit comments

Comments
 (0)