Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

@Rurban (Reini Urban): wrt to your first point, general purpose hash functions being modeled as PRNGs, I believe that statement to be correct. It is definitely the case when analysing hash function behaviour in contexts such as bloom filters, hash tables etc.

With regards to the definition of perfect hash functions - if you had read the sentence before the one you have quoted, you would have notice that the formal definition for a perfect hash function has been given in the article as:

> "In general there is a theoretical hash function known as the perfect hash function for any group of data. The perfect hash function by definition states that no collisions will occur meaning no repeating hash values will arise from different elements of the group."

It then goes on to talk about the practicalities of perfect hash functions (deriving them etc), then makes a statement that generally a perfect hash function is one that has the least collisions - I agree that it is an intentional weakening of the formal definition, but it is generally the most practical one - as there is no guarantee that one can always find a "perfect hash function" for any arbitrary set of values in sub-polynomial time.

----

wrt the collection of hash function, take note that the article is broken into the following sections:

1. What is a general purpose hash function

2. Designing and implementing general purpose hash functions

3. Uses of hash functions

4. Example general purpose hash functions (popular ones or written by leaders in the field, and dummies such as myself)

5. Downloads

So could you clarify what it is you meant by:

> " last section is a bit misleading. First he talks about hashing in general and then he introduces his implementations of hash functions"

what specifically was misleading in the article? I'm confused, could you please clarify.

----

wrt: > "DJB: "It is one of the most efficient hash functions ever published."

The statement is _not_ incorrect, it is indeed one of the most efficient hash functions out there, it may not be the MOST efficient or in other words "the number one hash function", but it's there at the top - I think you may have jumped the gun on that one too.

To further that, your comment: " Nonsense. FNV is considered the generally most efficient"

Lets have a look and see if that's true, the following are pseudo code representations of the mixes for each of the hash functions:

DJB: hash = ((hash << 5) + hash) + msg_byte

FNV1: hash = hash ^ msg_byte * FNV_prime

Unless you have a really bad shift operation (eg: having no barrel shifter present), then I can't see how FNV1 can be significantly more efficient than DJB - but then again, the compiler may optimize the shift right by 5 as a multiply by 32 for targets where the mul is faster than the shift...

But lets step back a bit and consider the following:

Is hash function efficiency that important when neither of the hash functions DJB or FNV1 posses good distributive qualities?

https://research.neustar.biz/tag/hash-function/



ad 1: https://stackoverflow.com/questions/31954237/pseudo-random-g... has some answers.

ad 2: in most measurable stats fnv1 is better than djb. practical throughput, time if inlined, cachegrind cost model (4x!). fnv also produces less collisions with average keys. only in pure cycle/hash djb is a bit better.

https://github.com/rurban/smhasher#smhasher https://github.com/rurban/perl-hash-stats#perl-hash-stats

> ad 3: Is hash function efficiency that important when neither of the hash functions DJB or FNV1 posses good distributive qualities?

It depends entirely on the use case. Usage in hash tables is totally different to usage as file or block checksum or crypto. Besides looking how many bis of the keys are really used or how easy it is to create collisions, it also depends if the keys are random length strings, aligned buffers or plain integers. Both DJB and FNV1 are considered bad regarding their stats. But they are small and fast.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: