Packages
rendezvous
0.0.1
Implementation of the Rendezvous or Highest Random Weight (HRW) hashing algorithm
Current section
Files
Jump to
Current section
Files
lib/rendezvous.ex
defmodule Rendezvous do
def get algorithm, key, buckets do
{bucket, _hash} = Enum.map(buckets, fn(b) -> get_bucket_with_hash(algorithm, b, key) end)
|> Enum.max_by fn {_b, hash} -> hash end
bucket
end
defp get_bucket_with_hash(algorithm, bucket, key) do
{bucket, compute_bucket_hash(algorithm, bucket, key)}
end
defp compute_bucket_hash(algorithm, bucket,key) do
:crypto.hash(algorithm,[bucket,key] )
end
end