Solved

How to use this hash table

Posted on 2008-06-23
7
355 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why isn't my scanf halting the execution of code in my C program? 6 274
Need example 5 107
xamarin c# deserialize Json containing nested object 2 80
Unable to start eclipse ? 17 128
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.

929 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

12 Experts available now in Live!

Get 1:1 Help Now