Skip to content

Instantly share code, notes, and snippets.

@teivah
Last active April 30, 2020 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teivah/ef584f41e30728aaa1cb9b2648480226 to your computer and use it in GitHub Desktop.
Save teivah/ef584f41e30728aaa1cb9b2648480226 to your computer and use it in GitHub Desktop.
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) {
int64_t b = ­1, j = 0;
while (j < num_buckets) {
b=j;
key = key * 2862933555777941757ULL + 1; // Did you say magic number?
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1));
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment