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

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. 好一点

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

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

posted on 2014-08-28 06:30  brave_bo  阅读(275)  评论(0)    收藏  举报

导航