We help IT Professionals succeed at work.

hash table problem

on
274 Views
hi,

i have done a hash table where i used this formula to index the table:

i added the ascii values of the word and did a modulus operator to get the index of the table.

example

(ascii value of c + ascii value of a + ascii value of t)% table size

the problem is that the formula is not too good as you get the linear link list.

is there any there formula that could be used....

i would be passing the values of the asciii values?

thanks
Comment
Watch Question

View Solution Only

CERTIFIED EXPERT
Top Expert 2006

Commented:
This hash function is good, it comes with a complete implementation
http://burtleburtle.net/bob/hash/doobs.html
http://burtleburtle.net/bob/c/lookup3.c

Commented:
hi,

is it the correct way of using , i am getting segmentation fault...

h = hashlittle(word, strlen(word)-1, h)

Commented:
i am getting a negative value for h...
CERTIFIED EXPERT
Top Expert 2006

Commented:

The call is correct - note that you are hashing strlen()-1 characters.

You cant get a negative value - it returns an *unsigned* int ... Use an unsigned int to store the result

Commented:
trying..thanks

but the value that i get, wouldn't I need to divide the size of the hash table?

for example,

the size of my hash table is 100

h = hashlittle(word, strlen(word), h);

h=h%100;

btw, it says , h is a arbitary value or previous hash, could  i just send in the size of the hash table...

sorry for the number of questions....
CERTIFIED EXPERT
Top Expert 2006

Commented:
>wouldn't I need to divide the size of the hash table?
Yes you would need to mod it to hash table size or use something like double hashing to resolve collisions. Again you should keep track of how many elements are there in your hash table and what is the load factor. e.g. If you insert 1000 values in a hash table of size 100, even the most ideal hashing function would give you a minimum of 10 elements per index.

>sorry for the number of questions....
No issues  with that ... feel free to ask as many questions as you want until your original problem gets solved. I would be glad to help you to a solution

Commented:
thank you very much...

i dont know what the problem is :-(

when i read data it is fine, after a while, it gets stuck for a while and then , it continues to read...it seems like the hash table has list that has already become linear link list....so, i think that is the problem but I don't know...

i am trying to remove it to get stuck...

Commented:
the number of elements in the hash table is 849289 and the size of the hash table is 200.

maybe, that is causing it...

what to you think the hash value of this many elements should be....thank you....
CERTIFIED EXPERT
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)

Commented:
thank you very much..trying it out now..

Commented:
it is solved at last..thank you.,..

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Connect with Certified Experts to gain insight and support on specific technology challenges including:

• Troubleshooting
• Research
• Professional Opinions
Unlock the solution to this question.

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.