Fix Murmur2 hash implementation

This commit is contained in:
comp500 2019-12-23 16:20:38 +00:00
parent c89d3b1e47
commit 432bb4e25f
2 changed files with 6 additions and 6 deletions

View File

@ -74,13 +74,13 @@ public class Murmur2Lib {
int left = length - len_m;
if (left != 0) {
if (left >= 3) {
h ^= (int) data[length - 3] << 16;
h ^= (int) data[length - (left - 2)] << 16;
}
if (left >= 2) {
h ^= (int) data[length - 2] << 8;
h ^= (int) data[length - (left - 1)] << 8;
}
if (left >= 1) {
h ^= (int) data[length - 1];
h ^= data[length - left];
}
h *= M_32;
@ -152,7 +152,7 @@ public class Murmur2Lib {
case 2:
h ^= (long) (data[tailStart + 1] & 0xff) << 8;
case 1:
h ^= (long) (data[tailStart] & 0xff);
h ^= data[tailStart] & 0xff;
h *= M_64;
}

View File

@ -29,8 +29,8 @@ class Murmur2Hasher : IHasher {
val output = ByteArray(input.size)
var index = 0
for (b in input) {
when (b.toInt()) {
9, 10, 13, 32 -> {}
when (b) {
9.toByte(), 10.toByte(), 13.toByte(), 32.toByte() -> {}
else -> {
output[index] = b
index++