Highest Random Weight in Elixir
6 points by susam
6 points by susam
Actually extremely interesting. I kinda want to take the code apart and see how it works for real. Seems like it's calling out for some kind of hash trie, so let's see if it matches my hunch.
Basic HRW is just repeated hashing, without a trie. The code is quoted in the article (phash2 is a hash function):
def owner(key, nodes) do
Enum.max_by(nodes, fn node ->
:erlang.phash2({key, node})
end)
end
The hierarchial variant for scaling up to lots of nodes is a tree but not a trie. A trie contains all its search keys, but here the tree contains just the server identifiers. The HRW tree search hashes the data key with all the identifiers at each internal node, using basic HRW for each step. Data keys are not known in advance, and there are many orders of magnitude more of them than server identifiers.