Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a fast hash-function

I'm looking for a special hash-function. Let's say I have a large list of strings, if I order them by their hash-values they should be ordered quasi randomly.

The most important point is: it must be super fast. I've tried md5 and sha1 and they're using to much cpu power.

Clashes are not a problem.

I'm using javascript, so it shouldn't be too complicated to implement.

like image 539
Julian Avatar asked Apr 04 '10 20:04

Julian


People also ask

How do you find a good hash function?

Characteristics of a Good Hash Function. There are four main characteristics of a good hash function: 1) The hash value is fully determined by the data being hashed. 2) The hash function uses all the input data. 3) The hash function "uniformly" distributes the data across the entire set of possible hash values.

Should a hash function be fast?

A good hash function satisfies two basic properties: 1) it should be very fast to compute; 2) it should minimize duplication of output values (collisions).

Is MD5 faster than SHA-256?

MD5 is known to be generally faster than SHA256 .

Is MD5 fast?

MD5 can have 128 bits length of message digest. Whereas SHA1 can have 160 bits length of message digest. 3. The speed of MD5 is fast in comparison of SHA1's speed.


2 Answers

Take a look at Murmur hash. It has a nice space/collision trade-off:

http://sites.google.com/site/murmurhash/

like image 184
Nils Pipenbrinck Avatar answered Oct 12 '22 17:10

Nils Pipenbrinck


It looks as if you want the sort of hash function used in a hash table, not the sort used to detect duplicates or tampering.

Googling will yield you a wealth of information on alternative hash functions. To start with, stay away from cryptographic signature hashes (like MD-5 or SHA-1), they solve another problem.

You can read this, or this, or this, to start with.

like image 38
bmargulies Avatar answered Oct 12 '22 19:10

bmargulies