473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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;
}
Nov 25 '05 #1
22 5607
"vietor.liu" <vi********@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.
Nov 25 '05 #2
On Fri, 25 Nov 2005 10:21:54 +0800, "vietor.liu"
<vi********@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
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
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*****@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.
Dec 5 '05 #7
Christopher Benson-Manica wrote:
Joe Estock <je*****@nospamnutextonline.com> 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.
Dec 5 '05 #8
Christopher Benson-Manica wrote:

Joe Estock <je*****@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
Dec 5 '05 #9

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

Dec 5 '05 #10
On Mon, 05 Dec 2005 15:49:26 +0100, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
Christopher Benson-Manica wrote:
And what is the airspeed velocity of an unladen swallow?

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


rofl!!!
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 5 '05 #11
On Mon, 5 Dec 2005 14:44:43 +0000 (UTC), in comp.lang.c , Christopher
Benson-Manica <at***@nospam.cyberspace.org> wrote:
Joe Estock <je*****@nospamnutextonline.com> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?


African or European? http://www.style.org/unladenswallow/
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 5 '05 #12
On 2005-12-05, Joe Estock <je*****@NOSPAMnutextonline.com> wrote:
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.


It seems to me that he's responding to the question in the subject with
a rhetorical question, rather than responding to the body of the post he
is in reply to.
Dec 5 '05 #13
"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:dn**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
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


Buuuuurrrrp!

Seriously, it was an answer to the post. How can one say what the best
hash function is without knowing the data? I think my answer was quite
appropos.

--
Mabden
Dec 6 '05 #14
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in
message news:dn**********@chessie.cirr.com...
Joe Estock <je*****@nospamnutextonline.com> wrote:
Red. No wait, Purple. On second thought, make that Green.


And what is the airspeed velocity of an unladen swallow?


http://www.style.org/unladenswallow/

"the average cruising airspeed velocity of an unladen European Swallow
is roughly 11 meters per second, or 24 miles an hour. "

--
Mabden
Dec 6 '05 #15
Mabden wrote:
"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:dn**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
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

Buuuuurrrrp!

Seriously, it was an answer to the post. How can one say what the best
hash function is without knowing the data? I think my answer was quite
appropos.


If enough of the original post were left in your reply then I would be
inclined to agree, however I had nothing but the text I replied to and
misinterpreted your reply. Yet another classic example of why you should
quote enough text from the previous post so that someone looking at the
thread for the very first time has enough information to understand your
reply. For all I know you could have been the OP replying to your
original thread.

Joe
Dec 6 '05 #16
"Joe Estock" <je*****@NOSPAMnutextonline.com> wrote in message
news:5H9lf.599651$x96.384071@attbi_s72...
Mabden wrote:
"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:dn**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
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
Buuuuurrrrp!

Seriously, it was an answer to the post. How can one say what the best hash function is without knowing the data? I think my answer was quite appropos.


If enough of the original post were left in your reply then I would be
inclined to agree, however I had nothing but the text I replied to and
misinterpreted your reply. Yet another classic example of why you

should quote enough text from the previous post so that someone looking at the thread for the very first time has enough information to understand your reply. For all I know you could have been the OP replying to your
original thread.

It really wouldn't help. The subject says it all, but here it is, in all
its 2-word glory:
======================
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;
}

======================

Now, does that really need to have been included. I think not.

I await your apology with anticip...
..
..
..
..
ation

--
Mabden
Dec 7 '05 #17
Mabden wrote:
[snip irrelevant stuff to my reply]
If enough of the original post were left in your reply then I would be
inclined to agree, however I had nothing but the text I replied to and
misinterpreted your reply. Yet another classic example of why you should
quote enough text from the previous post so that someone looking at
the thread for the very first time has enough information to understand
your reply. For all I know you could have been the OP replying to your
original thread.

It really wouldn't help. The subject says it all, but here it is, in all
its 2-word glory:
======================
is this?

[snip 14 lines of code for hash function]
======================

Now, does that really need to have been included. I think not.
I agree that it did not need to be included, however you could have at
least included some context such as [snip useless function] so that
others who do not have access to the original thread can better
understand why you replied as you did.

I await your apology with anticip... [snip gratuitous waste of newlines] ation


None needed since I said nothing that demands an apology. I was simply
pointing out that if you had quoted (or at least noted that you trimmed)
the original post that I would not have replied as I did. You don't read
the last message in a thread without first reading the original post and
neither do I.

Joe
Dec 8 '05 #18
On Thu, 08 Dec 2005 06:19:53 GMT, in comp.lang.c , Joe Estock
<je*****@NOSPAMnutextonline.com> wrote:
Mabden wrote:

I await your apology with anticip...

[snip gratuitous waste of newlines]


I fear the joke went over your head.
ation


None needed


And you shall recieve it, in abundance.

gd&r

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 8 '05 #19
On 2005-12-08, Joe Estock <je*****@NOSPAMnutextonline.com> wrote:

I await your apology with anticip...

[snip gratuitous waste of newlines]


it's not like we're killing trees, here - they probably only occupy a
byte apiece in storage and two over the wire. Your complaint was almost
certainly bigger.
ation

Dec 8 '05 #20
Jordan Abel <jm****@purdue.edu> writes:
On 2005-12-08, Joe Estock <je*****@NOSPAMnutextonline.com> wrote:
Mabden wrote:
I await your apology with anticip...

[snip gratuitous waste of newlines]

it's not like we're killing trees, here [...]


No, but think of all the instructions that were summarily executed in
the process!

DES
--
Dag-Erling Smørgrav - de*@des.no
Dec 9 '05 #21
On Fri, 09 Dec 2005 09:09:01 +0100, in comp.lang.c , de*@des.no
(Dag-Erling Smørgrav) wrote:
Jordan Abel <jm****@purdue.edu> writes:
On 2005-12-08, Joe Estock <je*****@NOSPAMnutextonline.com> wrote:
> Mabden wrote:
> > I await your apology with anticip...
> [snip gratuitous waste of newlines]

it's not like we're killing trees, here [...]


No, but think of all the instructions that were summarily executed in
the process!


I believe they used a thread to hang the processes.
And then stab'ed the remains with a fork.

<argh offtopic attack...>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 10 '05 #22
"Joe Estock" <je*****@NOSPAMnutextonline.com> wrote in message
news:dgQlf.609953$_o.26934@attbi_s71...
Mabden wrote:
[snip irrelevant stuff to my reply]
If enough of the original post were left in your reply then I would beinclined to agree, however I had nothing but the text I replied to andmisinterpreted your reply. Yet another classic example of why you shouldquote enough text from the previous post so that someone looking at
the thread for the very first time has enough information to understandyour reply. For all I know you could have been the OP replying to youroriginal thread.

It is my habit to be terse on fact and long on sarcasm that has labeled
me a troll on this newsgroup, to some. I tend to only argue points of
esoterica, while poking fun at newbies and those that make it their duty
to answer the unwashed masses. Your indignant response has become a
tiresomely customary adjunct to my posts. However, I'm sure you meant
only to improve the content of the newsgroup, as do I. ;-)

It really wouldn't help. The subject says it all, but here it is, in all its 2-word glory:
======================
is this?
[snip 14 lines of code for hash function]

======================

Now, does that really need to have been included. I think not.


I agree that it did not need to be included, however you could have at
least included some context such as [snip useless function] so that
others who do not have access to the original thread can better
understand why you replied as you did.


Ah. Yeah. I get a lot of that "in retrospect you did nothing wrong."
Unfortunately, I'm still killfiled a lot. I'm sure you can see for
yourself how one might begin to feel somewhat "misunderstood".
I await your apology with anticip...

[snip gratuitous waste of newlines]
ation


That was pure comedy. I cannot be responsible for your lack of a sense
of humor. >:-(
Go and see Rocky Horror Picture Show.

None needed since I said nothing that demands an apology. I was simply
pointing out that if you had quoted (or at least noted that you trimmed) the original post that I would not have replied as I did.
But then you admitted that the original post contained no content. So
you just commented to scold me. Am I not, human? Am I not a man with
pride? How can it be that you owe no apology? Is it up to me to fill you
in on all previous posts, so that you don't insult me?
You don't read the last message in a thread without
first reading the original post and
neither do I.


You don't know Jack about what I do, or how I do it. All you know is I
posted a reply to a post about what is the best hash function by
implying that one needs to pick it for themselves - there is no best
hash function just as there is no "best" color. Nothing I said was
incorrect or offensive.

What have you contributed to the discussion?

--
Mabden

Dec 10 '05 #23

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

Similar topics

220
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...
13
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
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
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...
21
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...
4
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
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...
6
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...
139
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.