hashperfect-hashgperf

Perfect hash function?


While reading the pigeonhole principle on Wikipedia, I come across - "collisions are inevitable in a hash table because the number of possible keys exceeds the number of indices in the array. No hashing algorithm, no matter how clever, can avoid these collisions". But isn't gperf doing this exactly?

Please enlighten.


Solution

  • gperf creates the hash function and the hash table basing on a predefined list of strings.

    It therefore appears to me that gperf creates the hashes long enough so that there are enough possibilities.
    That's what you can do only if you know every possible key upfront - which is an assumption which didn't hold for the description in the wikipedia's entry, which was apparently related to a "non-constant" hash-table.