We help IT Professionals succeed at work.

hash table problem

zizi21
zizi21 asked
on
274 Views
Last Modified: 2010-04-21
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

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

Author

Commented:
hi,

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

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

Author

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

Author

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

Author

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...


Author

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)
UNLOCK SOLUTION

Author

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

Author

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

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

Get Access
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

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

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

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
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

Ask ANY Question

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

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

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.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.