Skip to content

Instantly share code, notes, and snippets.

@creadone
Created April 26, 2023 23:13
Show Gist options
  • Select an option

  • Save creadone/e64d69de89cb16e0f13d53e4c8fed58e to your computer and use it in GitHub Desktop.

Select an option

Save creadone/e64d69de89cb16e0f13d53e4c8fed58e to your computer and use it in GitHub Desktop.

Revisions

  1. creadone created this gist Apr 26, 2023.
    12 changes: 12 additions & 0 deletions jump_consistent_hashing.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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