1

I am searching for a fast hash algorithm. Actually, I am trying to build a hash table whose keys are URL's. I have used MD5 to hash the URL's, however it is too slow (I have used java's built in function). Can anybody help me by informing about some fast hash algorithm.

3
  • What problem do you try to solve? Why is it too slow? How many hashes do you have to generate so you need a faster solution? PLease make some more comments so we can help you better. Commented Jul 31, 2011 at 23:28
  • Simple checksums should be fast, and if speed is a real issue, you can base it on a prefix (or suffix) of the URL. Commented Jul 31, 2011 at 23:29
  • As I said in your original question, if you want correctness, a standard hashing function alone isn't going to cut it. You either need to use a cryptographic hash, or store the original text (eg using a Trie). Commented Aug 1, 2011 at 3:39

3 Answers 3

6

Java's String class already implements .hashCode(). This is likely going to be the fastest, 32bit hash, for Java, as its heavily optimized at the core. This is also the hash in use when using the built-in collections, such as java.util.HashMap.

Sign up to request clarification or add additional context in comments.

1 Comment

but .hashCode() does not need to be unique, that has to be considered when using it!
3

Google open-sourced a very fast hashing algo: CityHash

Comments

0

MD5 is a cryptographic hash, so it will be slow compared to non-cryptographic hashes. As Yann says, the Java hash is likely to be fastest if you want a 64 bit hash.

If that doesn't suit then there are other fast non-cryptographic hashes available in various sizes, such as Fowler–Noll–Vo.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.