public class Sharded
{ private object nodes_lock = new object(); private RedBlackTreeMap nodes = new RedBlackTreeMap(); private IHash hashAlgo = new MD5_LongSUM_Multiply_Hash();
public void AddTarget(int index, string shard)
{ lock (nodes_lock)
{ for (int n = 0; n < 160; ++n)
{ var hashKey = "SHARD-" + index + "-NODE-" + n; long hashValue = this.hashAlgo.Hash(hashKey);
nodes.SetOrAddValue(hashValue, shard);
}
}
} public string GetShardInfo(string key)
{ long searchHashKey = this.hashAlgo.Hash(key); long nearestKey; string shard; lock (nodes_lock)
{ if (this.nodes.NearestGreater(searchHashKey, out nearestKey))