Skip to content

Instantly share code, notes, and snippets.

@creadone
Created April 26, 2023 23:13
Show Gist options
  • Save creadone/e64d69de89cb16e0f13d53e4c8fed58e to your computer and use it in GitHub Desktop.
Save creadone/e64d69de89cb16e0f13d53e4c8fed58e to your computer and use it in GitHub Desktop.
def jump_consistent_hash(key, num_buckets)
b = -1
j = 0
while j < num_buckets
b = j
key = (key * 2862933555777941757 + 1) % (2 ** 64)
j = ((b + 1) * (2 ** 31) / ((key >> 33) + 1)) % (2 ** 31)
end
b
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment