Implement Hash table

I went to German in XMas holidays. So the feature did not finished until tonight. I was shocked by hash algorithm again when I was implemented it. It is very simple and unbelivable powerful.

 

I got some code from internet when I was implementing it. Some numbers was attracting me. one is 31 when calculate hash code. The other is hash table size is use prime numbers. Why should use this values? Why need use prime numbers?

 

I searched on google and found two interesting web pages.

 

http://computinglife.wordpress.com/2008/11/20/why-do-hash-functions-use-prime-numbers/

http://www.concentric.net/~Ttwang/tech/primehash.htm.

 

It is not very easy to understand. Any way using it can minimize collisions. Tribute to Chen Jinglun & Hash.

 

你可能感兴趣的:(.net,Web,wordpress,Google)