Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  C语言  >  正文 Hash算法(KetamaHash)的c#实现

Hash算法(KetamaHash)的c#实现

发布时间:2018-11-07   编辑:www.jquerycn.cn
jquery中文网为您提供Hash算法(KetamaHash)的c#实现等资源,欢迎您收藏本站,我们将为您提供最新的Hash算法(KetamaHash)的c#实现资源
<blockquote>

public class hashalgorithm
{
    public static long hash(byte[] digest, int ntime)
    {
        long rv = ((long)(digest[3 ntime * 4] & 0xff) << 24)
                | ((long)(digest[2 ntime * 4] & 0xff) << 16)
                | ((long)(digest[1 ntime * 4] & 0xff) << 8)
                | ((long)digest[0 ntime * 4] & 0xff);

        return rv & 0xffffffffl; /* truncate to 32-bits */
    }

    /**
     * get the md5 of the given key.
     */
    public static byte[] computemd5(string k)
    {
        md5 md5 = new md5cryptoserviceprovider();
      
        byte[] keybytes = md5.computehash(encoding.utf8.getbytes(k));
        md5.clear();
        //md5.update(keybytes);
        //return md5.digest();
        return keybytes;
    }
}


public class ketamanodelocator
{
    //原文中的java类treemap实现了comparator方法,这里我图省事,直接用了net下的sortedlist,其中comparer接口方法)
    private sortedlist<long, string> ketamanodes = new sortedlist<long, string>();
    private hashalgorithm hashalg;
    private int numrehttp://www.111cn.net
            var tailmap = from coll in ketamanodes
                          where coll.key > hash
                          select new { coll.key };
            if (tailmap == null || tailmap.count() == 0)
                key = ketamanodes.firstordefault().key;
            else
                key = tailmap.firstordefault().key;
        }
        rv = ketamanodes[key];
        return rv;
   

</blockquote>

您可能感兴趣的文章:
php字符串哈希函数算法实现代码
Hash算法(KetamaHash)的c#实现
php hash算法实例分享
hash算法 consistent hashing 详解[图]
Go从入门到精通系列视频之go编程语言密码学哈希算法
MD5 hash algorithm function
一致性哈希算法的PHP实现代码
C语言实现的哈希表实现程序
WebQQ网页hash加密算法PHP版
java中双hash减少用户名冲突示例

[关闭]