Looking for a fast hash-function

2020-08-15 10:23发布

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.

4条回答
该账号已被封号
2楼-- · 2020-08-15 11:18

If speed is paramount, you can implement a simple ad-hoc hash, e.g. take the first and last letter and order your string by the last and then first letter. The result would look, as you say, "quasi random" and it would be fast. For instance, part of my answer sorted that way would look like this:

ca ad-hoc
el like
es simple
gt taking
hh hash
nc can
ti implement
uy you
查看更多
啃猪蹄的小仙女
3楼-- · 2020-08-15 11:24

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

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

查看更多
Rolldiameter
4楼-- · 2020-08-15 11:24

Hsieh, Murmur, Bob Jenkin's comes to my mind.
A nice page about hash functions that has some tests for quality and a simple S-box hash as well.

查看更多
老娘就宠你
5楼-- · 2020-08-15 11:26

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.

查看更多
登录 后发表回答