首页 > 编程语言 > 详细

分布均衡算法

时间:2017-04-06 15:38:08      阅读:173      评论:0      收藏:0      [点我收藏+]

1.移位实现

      public static int GetIndex(string str, int count)
        {
            int hash = str.Aggregate(23, (current, c) => (current << 5) - current + c);
            if (hash < 0)
            {
                hash = Math.Abs(hash);
            }
            return hash % count;
        }

2.GetHashCode()

      public static int GetIndex2(string str, int count)
        {
            int hash =str.GetHashCode();
            if (hash < 0)
            {
                hash = Math.Abs(hash);
            }
            return hash % count;
        }

 

分布均衡算法

原文:http://www.cnblogs.com/gaobing/p/6673547.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!