Velocity Reviews > what's the best hash function?

what's the best hash function?

vietor.liu
Guest
Posts: n/a

 11-25-2005
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&0xf0000000))
{
h^=(g>>24);
h^=g;
}
}
return h%size;
}

Chris McDonald
Guest
Posts: n/a

 11-25-2005
"vietor.liu" <(E-Mail Removed)> 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&0xf0000000))
> {
> 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.

Jack Klein
Guest
Posts: n/a

 11-25-2005
On Fri, 25 Nov 2005 10:21:54 +0800, "vietor.liu"
<(E-Mail Removed)> 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&0xf0000000))
> {
> h^=(g>>24);
> h^=g;
> }
> }
> return h%size;
> }
>

If you want to know the "best" hashing algorithm, ask in
news:comp.programming. 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

--
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.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Mabden
Guest
Posts: n/a

 12-05-2005
What is the best colour?

--
Mabden

Joe Estock
Guest
Posts: n/a

 12-05-2005
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

Joe

Richard Heathfield
Guest
Posts: n/a

 12-05-2005
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)

Christopher Benson-Manica
Guest
Posts: n/a

 12-05-2005
Joe Estock <(E-Mail Removed)> 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)cyberspace.org | don't, I need to know. Flames welcome.

Skarmander
Guest
Posts: n/a

 12-05-2005
Christopher Benson-Manica wrote:
> Joe Estock <(E-Mail Removed)> wrote:
>
>> Red. No wait, Purple. On second thought, make that Green.

>
> And what is the airspeed velocity of an unladen swallow?
>

off-topic for this group. You may have more success getting answers in
comp.lang.python -- this may be a FAQ there.

S.

pete
Guest
Posts: n/a

 12-05-2005
Christopher Benson-Manica wrote:
>
> Joe Estock <(E-Mail Removed)> 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

David Resnick
Guest
Posts: n/a

 12-05-2005

Christopher Benson-Manica wrote:
> Joe Estock <(E-Mail Removed)> 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)cyberspace.org | don't, I need to know. Flames welcome.

This really sounds like homework. Besides, it is an algorithm
question, so comp.programming 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