Ejemplo n.º 1
0
        public string GetPrimary(string k)
        {
            byte[] digest = HashAlgorithmMD5.computeMd5(k);
            string rv     = GetNodeForKey(HashAlgorithmMD5.hash(digest, 0));

            return(rv);
        }
Ejemplo n.º 2
0
        //此处参数与JAVA版中有区别,因为使用的静态方法,所以不再传递HashAlgorithmMD5 alg参数
        public KetamaNodeLocator(List <string> nodes /*, int nodeCopies*/)
        {
            ketamaNodes = new SortedList <long, string>();

            //numReps = nodeCopies;
            //对所有节点,生成nCopies个虚拟结点
            foreach (string node in nodes)
            {
                //每四个虚拟结点为一组
                for (int i = 0; i < numReps / 4; i++)
                {
                    //getKeyForNode方法为这组虚拟结点得到惟一名称
                    byte[] digest = HashAlgorithmMD5.computeMd5(node + i);
                    /** Md5是一个16字节长度的数组,将16字节的数组每四个字节一组,分别对应一个虚拟结点,这就是为什么上面把虚拟结点四个划分一组的原因*/
                    for (int h = 0; h < 4; h++)
                    {
                        long m = HashAlgorithmMD5.hash(digest, h);
                        ketamaNodes[m] = node;
                    }
                }
            }
        }