473,581 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what's the best hash function?

is this?

int hashpjw(char* str,int size)
{
unsigned long h=0,g;
for(unsigned char *p=(unsigned char*)str;*p;++ p)
{
h=(h<<4)+*p;
if(g=(h&0xf0000 000))
{
h^=(g>>24);
h^=g;
}
}
return h%size;
}
Nov 25 '05 #1
22 5627
"vietor.liu " <vi********@gma il.com> writes:
is this? int hashpjw(char* str,int size)
{
unsigned long h=0,g;
for(unsigned char *p=(unsigned char*)str;*p;++ p)
{
h=(h<<4)+*p;
if(g=(h&0xf0000 000))
{
h^=(g>>24);
h^=g;
}
}
return h%size;
}

<OT>
The answer totally depends on the type and range of inputs,
and the purpose of the hash result. Read onwards:

http://burtleburtle.net/bob/hash/evahash.html
</OT>

--
Chris.
Nov 25 '05 #2
On Fri, 25 Nov 2005 10:21:54 +0800, "vietor.liu "
<vi********@gma il.com> wrote in comp.lang.c:

Define "best".
is this?

int hashpjw(char* str,int size)
{
unsigned long h=0,g;
for(unsigned char *p=(unsigned char*)str;*p;++ p)
{
h=(h<<4)+*p;
if(g=(h&0xf0000 000))
{
h^=(g>>24);
h^=g;
}
}
return h%size;
}


If you want to know the "best" hashing algorithm, ask in
news:comp.progr amming. And supply a definition of what you consider
to be "best".

Once you have selected an algorithm, if you have problems coding it
correctly in standard C, then you can post your code and description
of your problem here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 25 '05 #3
What is the best colour?

--
Mabden
Dec 5 '05 #4
Mabden wrote:
What is the best colour?


Red. No wait, Purple. On second thought, make that Green.

I have no idea what it is you are asking since both the subject line and
the body of your post are completely different and no context is
provided in either. Please be more descriptive when you post as it helps
us better help you.

Joe
Dec 5 '05 #5
Joe Estock said:
Mabden wrote:
What is the best colour?


Red. No wait, Purple. On second thought, make that Green.


' . .
ea e o ee e o a
Pl s d n t f d th tr lls Th nks

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 5 '05 #6
Joe Estock <je*****@nospam nutextonline.co m> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 5 '05 #7
Christopher Benson-Manica wrote:
Joe Estock <je*****@nospam nutextonline.co m> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?

Please read http://www.ungerhu.com/jxh/clc.welcome.txt. Your question is
off-topic for this group. You may have more success getting answers in
comp.lang.pytho n -- this may be a FAQ there.

S.
Dec 5 '05 #8
Christopher Benson-Manica wrote:

Joe Estock <je*****@nospam nutextonline.co m> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?


http://faultgame.com/images/quest.wav

--
pete
Dec 5 '05 #9

Christopher Benson-Manica wrote:
Joe Estock <je*****@nospam nutextonline.co m> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.


This really sounds like homework. Besides, it is an algorithm
question, so comp.programmin g would be a better place.
Maybe you should try to write a C program to calculate
the average velocity of a number of swallows. If you
present your efforts, I'm sure people will try to give you a
hand. <OT> Hint -- it matters whether it is African or
European </OT>

-David

Dec 5 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18931
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it...
13
2297
by: gtux | last post by:
Hi everybody: I'm new in Javascript, I found some code and there is this: var fruit = { 'apple' : { 'weight' : 10, 'cost' : 9}, 'peach' : { 'weight' : 19, 'cost' : 10} }
96
6188
by: BadPony | last post by:
Anyone using Peoplesoft on a Federated UDB (shared nothing)Environment on Open System Platforms? Preferably AIX, but any war stories would be good. TEA EB-C
21
13810
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash...
21
3187
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been...
4
4899
by: yuyang08 | last post by:
Hello, everyone, I am wondering what is the hash function that is used in hash_map/hash_set. Can I replace it with my own hash function? Any comments on this? Thanks! -Andy
21
3866
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that applies in this case though: #include <limits.h> unsigned foo(void) { static const union { unsigned char str;
6
16865
by: fdmfdmfdm | last post by:
This might not be the best place to post this topic, but I assume most of the experts in C shall know this. This is an interview question. My answer is: hash table gives you O(1) searching but according to your hash function you might take more memory than binary tree. On the contrary, binary tree gives you O(logN) searching but less...
139
14087
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
0
7792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3805
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.