Merge pull request #2616 from morn-0/v5-dev

修复 murmur3 32 实现错误
This commit is contained in:
Golden Looly 2022-09-20 16:14:25 +08:00 committed by GitHub
commit 0c6ea1b3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -95,11 +95,11 @@ public class MurmurHash implements Serializable{
int k1 = 0;
switch (length - idx) {
case 3:
k1 ^= data[idx + 2] << 16;
k1 ^= (data[idx + 2] & 0xff) << 16;
case 2:
k1 ^= data[idx + 1] << 8;
k1 ^= (data[idx + 1] & 0xff) << 8;
case 1:
k1 ^= data[idx];
k1 ^= (data[idx] & 0xff);
// mix functions
k1 *= C1_32;

View File

@ -9,15 +9,15 @@ public class MurMurHashTest {
@Test
public void hash32Test() {
int hv = MurmurHash.hash32(StrUtil.utf8Bytes(""));
Assert.assertEquals(222142701, hv);
Assert.assertEquals(-1898877446, hv);
hv = MurmurHash.hash32(StrUtil.utf8Bytes("你好"));
Assert.assertEquals(1188098267, hv);
Assert.assertEquals(337357348, hv);
hv = MurmurHash.hash32(StrUtil.utf8Bytes("见到你很高兴"));
Assert.assertEquals(-1898490321, hv);
Assert.assertEquals(1101306141, hv);
hv = MurmurHash.hash32(StrUtil.utf8Bytes("我们将通过生成一个大的文件的方式来检验各种方法的执行效率因为这种方式在结束的时候需要执行文件"));
Assert.assertEquals(-1713131054, hv);
Assert.assertEquals(-785444229, hv);
}
@Test