How to hash strings of chars and integers in hash table -
i trying hash strings names containing 2 letters , 4 digit. example names (strings): az5466 ge1890 ru0291
and save them in hash table.
i thought if there way refer string integer number, can make: (name % 10) - example , hash them in array size 10 of linked lists.
using c language.
you can convert each character ascii code , multiply.
for example, in case, can write like:
int number = ((name[0] - 'a') * ('z' - 'a' + 1) + (name[1] - 'a')) * 10000 + atoi(name + 2);
the code assumes letters capital.
by way, should check if converting integer , modulo enough (you need make sure you'll have approximatelly same number of elements in each bucket).
if want, can split them more first or letter:
hash = (name[0] - 'a')
will give number between 0 , 25 (according first letter), and
hash = (name[5] - '0')
will give same results converting integer (the way i've suggested) , perform modulo 10.
Comments
Post a Comment