Skip to content

Instantly share code, notes, and snippets.

@ayende
Created June 4, 2016 16:20
Show Gist options
  • Save ayende/0e996a6bf57dc7c56e38758f1e30f391 to your computer and use it in GitHub Desktop.
Save ayende/0e996a6bf57dc7c56e38758f1e30f391 to your computer and use it in GitHub Desktop.
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;
}
@ayende
Copy link
Author

ayende commented Jul 1, 2020

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