Solved

How to use this hash table

Posted on 2008-06-23
7
354 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements 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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now