Solved

How to use this hash table

Posted on 2008-06-23
7
365 Views
Last Modified: 2010-04-15
Hi experts,

I am researching hash functions on http://www.burtleburtle.net/bob/c/lookup3.c. Assume that I use hash function hashlittle() and I have some key words like "this", "is", "yahoo",  can somebody give me an example how to put these keywords into hash and then retrieve them from hash?

Thanks a lot!
0
Comment
Question by:davidw88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 21850813
That source code just offers several ways of generating a hash value. It doesn't actually implement a hash table.

If what you're looking for is simply how to generate a hash for a keyword, then that could be :

const char *keyword = "Yahoo";
uint32_t hash = hashlittle(keyword, strlen(keyword), 0x12345678);

Open in new window

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21850817
>> and then retrieve them from hash?

A hash is one-way - ie. you can't get the "Yahoo" keyword out of the hash.
0
 

Author Comment

by:davidw88
ID: 21851098
hi I8,

Thanks so much for your clarification. Yes, they are just hash functions creating hash values. hashlittle(...) may generate either positive or nagative values.

When I said "hash", I actually meant "hash table". I should be more accurate in future.

Now I need to save this information "this", "is", "yahoo" so that later I can check. With these hash function values, I would like to implement a hash table. Do you have any suggestions on how to do this? especially how to handle the nagative hash function values?

Thanks again.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:davidw88
ID: 21851226
Just a general guess: If I implement a hash table, can the overhead of this hash table beat the overhead of the hash table from Gnome Library?

This is what I conern. If it can not, then it is meaningless to implement a hash table. From my experience, I found the hash table from GLib really has a very heavy overhead.

Any ideas?
0
 

Author Comment

by:davidw88
ID: 21851254
Now that I know how to implement a hash table, I just wonder if it is worth to do so. At this time I use GLib hash tables.

I appreciate all replies and comments.

Thanks so much.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 21852449
I haven't used glibc hash tables, I use custom implementation. You can begin by simply replacing the hash function being used ... If that does not help, you can probably try replacing the hash tables. Ideally hash tables should not be the pain point.

It would be a very good idea to profile your program and the hashing (if possible). That would give a very clear idea as to where you should be spending your energies .... no point in rewriting the hash tables when your bottleneck is say your search collation function
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 125 total points
ID: 21852785
These hash functions you posted return 32bit hash values. For use in a hash table, that might not be very handy (unless you take into account only a part of the hash value to fit the size of your hash table).


>> If I implement a hash table, can the overhead of this hash table beat the overhead of the hash table from Gnome Library?

Yes, because you can make a specifically tailored hash table that is optimized for your situation. Any common hash table implementation is done for general purposes, thus likely less efficient in the specific case.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question