Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   what's the best hash function? (http://www.velocityreviews.com/forums/t440281-whats-the-best-hash-function.html)

 vietor.liu 11-25-2005 02:21 AM

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

 Chris McDonald 11-25-2005 02:51 AM

Re: what's the best hash function?

"vietor.liu" <vietor.liu@gmail.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&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 11-25-2005 05:39 AM

Re: what's the best hash function?

On Fri, 25 Nov 2005 10:21:54 +0800, "vietor.liu"
<vietor.liu@gmail.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&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 12-05-2005 07:47 AM

Re: what's the best hash function?

What is the best colour?

--
Mabden

 Joe Estock 12-05-2005 09:10 AM

Re: what's the best hash function?

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 12-05-2005 09:27 AM

Re: what's the best hash function?

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 12-05-2005 02:44 PM

Re: what's the best hash function?

Joe Estock <jestock@nospamnutextonline.com> 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 12-05-2005 02:49 PM

Re: what's the best hash function?

Christopher Benson-Manica wrote:
> Joe Estock <jestock@nospamnutextonline.com> 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 12-05-2005 02:52 PM

[ot]Re: what's the best hash function?

Christopher Benson-Manica wrote:
>
> Joe Estock <jestock@nospamnutextonline.com> 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 12-05-2005 02:58 PM

Re: what's the best hash function?

Christopher Benson-Manica wrote:
> Joe Estock <jestock@nospamnutextonline.com> 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

All times are GMT. The time now is 08:22 PM.