Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
Programming

String Hash functions

jaderamiso
Wednesday, December 22, 2010 - 00:21

does anyone know any good string hash functions??

  • Log in or register to post comments
Robin
joined 16 years 2 weeks ago
Wednesday, December 22, 2010 - 01:41
Robin's picture

I think it depends on what you want to do with it on what is a good hash function.

  • Log in or register to post comments
jaderamiso
joined 14 years 7 months ago
Wednesday, December 22, 2010 - 02:41

well, i want to use it on a hash table..

ill be using it in creating a symbol table

  • Log in or register to post comments
Pompei2
joined 15 years 5 months ago
Wednesday, December 22, 2010 - 03:48
Pompei2's picture

Depends on the allowed size of the hash, the data to hash, and the amount of collisions you can deal with.

"string" is very generic: only a-zA-Z, or full ASCII, or even full unicode strings?

If the hash size is allowed to be big, you might aswell use a full MD5 or SHA-family algorithm.

If the hash size should be rather small (like, an integer), there is the category of CRC algorithms (for example CRC32 generates one 32-bit integer checksum), I read Adler32 or Fletcher are slightly better than CRC32

Hope that helps.

  • Log in or register to post comments
bart
joined 13 years 10 months ago
Wednesday, December 22, 2010 - 06:01
bart's picture

If you're okay with collisions and you just want to sort them into a bunch of buckets, one thing you can do is, say, hash them by the first character.  This is, of course, assuming that the strings are relatively random.  If you want to be as fast as possible, my general advice is to pick something that you expect to be different about each string and write a custom has function based on that.  If you need to avoid collisions at all costs, use an existing algorithm. :)

  • Log in or register to post comments
jaderamiso
joined 14 years 7 months ago
Monday, January 3, 2011 - 06:53

thanks for the reply! i did found several algorithms, im currently checking their performance. As for preventing collisions i plan on using chaining.

  • Log in or register to post comments