0

Possible Duplicate:
What's a good hash function for English words?

I want to calculate the frequency of any word in a text file. I solved this problem using BST. I want to solve this using hash table. Can you tell me the hash function. So that all same words store in a single key. Thanks.

Community
  • 1
  • 1
devsda
  • 3,936
  • 9
  • 49
  • 83
  • 1
    Most hash functions aren't "perfect", there will be collisions. – unwind Jun 25 '12 at 10:21
  • 2
    For a restricted set like this one, there are perfect hashing functions which can be used. Anyway, why you need to hash the words? Why not use the word themselves? – m0skit0 Jun 25 '12 at 10:23
  • Collision is a problem that you'll have to deal with, so this would decrease performance a bit. Personally I doubt that you'll get a better algorithm than putting all the strings into a std::vector and using std::sort and finally a quick counting loop. – stefan Jun 25 '12 at 10:28
  • There is an [excellent answer](http://programmers.stackexchange.com/q/49550/44705) on the `programmers` site. – Sergey Kalinichenko Jun 25 '12 at 11:06

0 Answers0