Hashing the elite....

Wednesday, 21 March 2012
Hash code-maps:
1.Hash function has two components:
->hash code maps
->compression map
Hash code map changes the key to integer value for using as array indices.
Compression map brings the integer to the range of our array indices.

2.Popular hash code maps:
->Integer cast: If numeric type with 32 bits or less take integer cast as inteeger
->Component Sum:If num is more than 32 bits we could take 32 bits at a time and add
their sum... to get our integer
->Polynomial accumulation:for strings..commbine the ascii values and use them as
co-efficients of polynomial a0+a1x+.. for a certain value of x.The choice of x=33
,37,39 or 41 is likely to give less collissions.

3.Compression maps:
->k mod m:donot take m as power of two or close to a poweer of two as mod 2
is giving the last bits of a data which however could be same for a large
number of numbers.Take the size of the table as a prime number.
->h(k)=|m(k A mod )|
k is the key m is the size of table and a is between 0 and
value of m is not critical can use a power of two.Using a as golden ratio
is known as fibonnaci hashing
->h(k)=|ak+b|mod n known as multiply add and divide(MAD).n is the size of hash
table and a and b are any numbers.Here a should not be a multiple of n or else we will get
b everytime.K could be the initial time.

Copyright @ 2013 code-craft. Designed by Templateism | MyBloggerLab