So I have a collision-less hash function (a very simple one) and I'm wondering why collision-less hash functions like this aren't used. I'm guessing that the reason must be that it takes up too much space or something, but I'd like to know the real answer.
Here's the function:
If you have a word w composed of n+1 characters ßn ßn-1 ... ß1 ß0, then define the hash function
H(w) = 26n * ßn + 26n-1 * ßn-1 + ... + 26 * ß1 + ß0.
where, for instance, a = 1, b = 2, c = 3, ..., z = 26.
This function has no collisions, as it defines a one-to-one mapping between a String and the integers.
The issue of course is that as the length of the word increases, the hash code becomes very large.
A possible solution to this would be: split up long words and make each hash code a vector, with the second element pointing to the rest of the word (which in turn could point to another part of the word if it was split up more than once).
So my question is: why is this not implemented? Was the extra cost of memory not worth avoiding collisions? Was this method found to be poor for another reason? Am I the first one to think of doing it this way? (Just kidding about that last one.)