forked from ben-manes/caffeine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f65e91
commit 98c154b
Showing
4 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...m/github/benmanes/caffeine/cache/simulator/policy/latency_aware/pipeline/XXH3Sampler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.benmanes.caffeine.cache.simulator.policy.latency_aware.pipeline; | ||
import com.dynatrace.hash4j.hashing.Hasher64; | ||
import com.dynatrace.hash4j.hashing.XXH3_64; | ||
import com.dynatrace.hash4j.hashing.HashFunnel; | ||
|
||
public class XXH3Sampler implements LongSampler{ | ||
private HashFunnel<Long> funnel = (o, sink) -> sink.putLong(o); | ||
private long mask; | ||
|
||
private Hasher64 hash; | ||
public XXH3Sampler(int order, long seed) { | ||
mask = createMask(order); | ||
hash = XXH3_64.create(seed); | ||
} | ||
|
||
@Override | ||
public boolean shouldSample(long key) { | ||
return (hash.hashToLong(key, funnel) & mask) == 0; | ||
} | ||
|
||
private static long createMask(int exp) { | ||
long mask = 0; | ||
for (int i = 0; i < exp; ++i) { | ||
mask = mask << 1 | 1; | ||
} | ||
|
||
return mask; | ||
} | ||
} |