首页 > 其他 > 详细

hash function 3种方法 1不好 2一般 3好

时间:2014-08-28 07:24:49      阅读:282      评论:0      收藏:0      [点我收藏+]

1. h(k) =  k mod m    

its is really bad in the practical. if m = even and k is all even....

( m is size of hash table,  

modulo

[‘m?djul?u

)

 

2. multiplication method. 好一点

bubuko.com,布布扣

a multiplice the k and sum mod 2^w  w is the bit length integer.  two power of two.

 

3. Universal hashing.

h(k) = [(a*k + b) mod p] mod m         p is a prime number.  p>m   a,b random from 0-p-1

bubuko.com,布布扣

 h(k1)=h(k2)    probability <= 1/m

hash function 3种方法 1不好 2一般 3好

原文:http://www.cnblogs.com/leetcode/p/3940716.html

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