Hash tables...ah yes :)
The reason you use prime numbers is for certain collision resolving algorithms(mostly). Anyway, they don''t _have_ to be that size, it just helps certain algorithms. If you use stacks to resolve collisions, then the benefits are mostly gone.
If you resize the table later, you still have to rehash everything. I would suggest that if you know the order of magnitude of the "average" case, optimize your initial table size for that range.
A good book on algorithms(available from any university bookstore of a school offering first year computer science courses) is a must have for any programmer(reference value alone), and it explains why primes are good for certain hashing algorithms. Anyway, you''re hash function ought to not make a lot of collisions .
I believe I might have a dusty old Data Structures book floating around that should have them Have to see if I can find it.
Thanks,
Derrick
You could always use a cryptographic hash(MD5?) function, they''re designed to prevent collisions . Actually, probably just take every 2 bytes of your string and keep a running XOR, pad the last block with the character from the beginning of the string. Mod your hash table size.
Oh yeah, I recalled why primes were good, FYI, if you jump ahead until you find an empty block, the algorithm people suggest using a quadratic function(look 1 ahead, 2 ahead, 9 ahead, 16 ahead). Anyway, you won''t run into factors of anything producing collisions, something like that, flame me, whatever, just trying to be informative .