Created
June 4, 2016 16:20
-
-
Save ayende/0e996a6bf57dc7c56e38758f1e30f391 to your computer and use it in GitHub Desktop.
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
private static int JumpConsistentHash(ulong key, int numBuckets) | |
{ | |
ulong choosenBucket = ulong.MaxValue; | |
ulong index = 0; | |
while (index < (ulong) numBuckets) | |
{ | |
choosenBucket = index; | |
key = key * 2862933555777941757UL + 1; | |
index = (ulong)((choosenBucket + 1) * (double)(1L << 31) / (key >> 33) + 1); | |
} | |
return (int)choosenBucket; | |
} |
You're welcome. Note that this is translation from this paper: https://arxiv.org/ftp/arxiv/papers/1406/1406.2294.pdf
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this piece of code!