Skip to content

Commit 00b1503

Browse files
committed
fix hash function and write it in a clearer, more explicit style
1 parent 4e71475 commit 00b1503

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

caffeine/src/main/java/com/github/benmanes/caffeine/cache/FrequencySketch.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,19 @@ public void increment(E e) {
167167

168168
/** Applies a supplemental hash functions to defends against poor quality hash. */
169169
int spread(int x) {
170-
x = ((x >>> 17) ^ x) * 0xed5ad4bb;
171-
x = ((x >>> 11) ^ x) * 0xac4c1b51;
172-
return (x >>> 15) ^ x;
170+
x ^= x >>> 17;
171+
x *= 0xed5ad4bb;
172+
x ^= x >>> 11;
173+
x *= 0xac4c1b51;
174+
x ^= x >>> 15;
175+
return x;
173176
}
174177

175178
/** Applies another round of hashing for additional randomization. */
176179
int rehash(int x) {
177-
return 0x31848bab * (x >>> 14) ^ x;
180+
x *= 0x31848bab;
181+
x ^= x >>> 14;
182+
return x;
178183
}
179184

180185
/**

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ext {
8787
]
8888
pluginVersions = [
8989
bnd: '6.3.1',
90-
checkstyle: '10.3.3',
90+
checkstyle: '10.3.4',
9191
coveralls: '2.12.0',
9292
dependencyCheck: '7.2.1',
9393
errorprone: '2.0.2',

0 commit comments

Comments
 (0)