码迷,mamicode.com
首页 > 编程语言 > 详细

分布均衡算法

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

标签:div   int   abs   hash   tin   移位   dex   log   mat   

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;
        }

 

分布均衡算法

标签:div   int   abs   hash   tin   移位   dex   log   mat   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!