Created
January 25, 2017 14:41
-
-
Save MikeGoldsmith/a6821184d74eafff53fb9db3a8b1d6ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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