How do I calculate a good hash code for a list of strings?

Posted by Ian Ringrose on Stack Overflow See other posts from Stack Overflow or by Ian Ringrose
Published on 2010-04-28T15:26:55Z Indexed on 2010/04/28 15:33 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

Background:

  • I have a short list of strings.
  • The number of strings is not always the same, but are nearly always of the order of a “handful”
  • In our database will store these strings in a 2nd normalised table
  • These strings are never changed once they are written to the database.

We wish to be able to match on these strings quickly in a query without the performance hit of doing lots of joins.

So I am thinking of storing a hash code of all these strings in the main table and including it in our index, so the joins are only processed by the database when the hash code matches.

So how do I get a good hashcode? I could:

  • Xor the hash codes of all the string together
  • Xor with multiply the result after each string (say by 31)
  • Cat all the string together then get the hashcode
  • Some other way

So what do people think?

(If you care we are using .NET and SqlServer)

© Stack Overflow or respective owner

Related posts about hashcode

Related posts about database-design