Skip to content

Instantly share code, notes, and snippets.

@MikeGoldsmith
Created January 25, 2017 14:41
Show Gist options
  • Save MikeGoldsmith/a6821184d74eafff53fb9db3a8b1d6ce to your computer and use it in GitHub Desktop.
Save MikeGoldsmith/a6821184d74eafff53fb9db3a8b1d6ce to your computer and use it in GitHub Desktop.
using (var md5 = MD5.Create())
{
foreach (var server in _servers.Values.Where(x => x.IsDataNode))
{
const long repititions = 40;
for (long rep = 0; rep < repititions; rep++)
{
var bytes = Encoding.UTF8.GetBytes(string.Format("{0}-{1}", server.EndPoint, rep));
var hash = md5.ComputeHash(bytes);
for (var j = 0; j < 4; j++)
{
var key = ((long) (hash[3 + j * 4] & 0xFF) << 24)
| ((long) (hash[2 + j * 4] & 0xFF) << 16)
| ((long) (hash[1 + j * 4] & 0xFF) << 8)
| (uint) (hash[0 + j * 4] & 0xFF);
_buckets[key] = server;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment