Skip to content

Commit 4e4db7f

Browse files
committed
Update Murmur 3 from Commons Codec
1 parent e8d30a7 commit 4e4db7f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/com/rabbitmq/stream/impl/HashUtils.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
package com.rabbitmq.stream.impl;
1616

17+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1718
import java.nio.charset.StandardCharsets;
1819
import java.util.function.ToIntFunction;
1920

@@ -25,6 +26,7 @@ private HashUtils() {}
2526

2627
// from
2728
// https://github.com/apache/commons-codec/blob/rel/commons-codec-1.15/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java
29+
// hash32x86 method
2830
static class Murmur3 implements ToIntFunction<String> {
2931

3032
private static final int DEFAULT_SEED = 104729;
@@ -37,10 +39,10 @@ static class Murmur3 implements ToIntFunction<String> {
3739
private static final int N_32 = 0xe6546b64;
3840

3941
private static int getLittleEndianInt(final byte[] data, final int index) {
40-
return ((data[index] & 0xff))
41-
| ((data[index + 1] & 0xff) << 8)
42-
| ((data[index + 2] & 0xff) << 16)
43-
| ((data[index + 3] & 0xff) << 24);
42+
return data[index] & 0xff
43+
| (data[index + 1] & 0xff) << 8
44+
| (data[index + 2] & 0xff) << 16
45+
| (data[index + 3] & 0xff) << 24;
4446
}
4547

4648
private static int mix32(int k, int hash) {
@@ -70,6 +72,7 @@ private static int fmix32(int hash) {
7072
this.seed = seed;
7173
}
7274

75+
@SuppressFBWarnings({"SF_SWITCH_FALLTHROUGH", "SF_SWITCH_NO_DEFAULT"})
7376
@Override
7477
public int applyAsInt(String value) {
7578
byte[] data = value.getBytes(StandardCharsets.UTF_8);
@@ -94,7 +97,7 @@ public int applyAsInt(String value) {
9497
case 2:
9598
k1 ^= (data[index + 1] & 0xff) << 8;
9699
case 1:
97-
k1 ^= (data[index] & 0xff);
100+
k1 ^= data[index] & 0xff;
98101

99102
// mix functions
100103
k1 *= C1_32;

0 commit comments

Comments
 (0)