Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what's the best hash function?

Reply
Thread Tools

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;
}


 
Reply With Quote
 
 
 
 
Chris McDonald
Guest
Posts: n/a
 
      11-25-2005
"vietor.liu" <> 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.
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      11-25-2005
On Fri, 25 Nov 2005 10:21:54 +0800, "vietor.liu"
<> 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
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.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
Mabden
Guest
Posts: n/a
 
      12-05-2005
What is the best colour?

--
Mabden


 
Reply With Quote
 
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
us better help you.

Joe
 
Reply With Quote
 
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)
 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      12-05-2005
Joe Estock <> 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.
 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      12-05-2005
Christopher Benson-Manica wrote:
> Joe Estock <> 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.python -- this may be a FAQ there.

S.
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-05-2005
Christopher Benson-Manica wrote:
>
> Joe Estock <> 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
 
Reply With Quote
 
David Resnick
Guest
Posts: n/a
 
      12-05-2005

Christopher Benson-Manica wrote:
> Joe Estock <> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Where's the best version of Hash#pass and Hash#block? Phlip Ruby 9 03-09-2009 02:37 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
In 'HashMap.put', "if (e.hash == hash && eq(k, e.key))" ? Red Orchid Java 3 01-30-2006 07:04 PM
standard library for hash table storage and hash algorithm Pieter Claassen C Programming 1 08-04-2004 03:11 AM



Advertisments