The hashing functions use known algorithms to "parse" a string and produce a fixed size output. In the examples you gave the output would be a 32bit (unsigned) integer. This means that collisions can occur if your string is too long. Technically, depending on the algorithm used it doesn't necessarily collide when the possibilities of the string exceed the 32 bit integer limit (4294967295).
Even with a perfect algorithm, you are guaranteed to be at risk of collisions when you hash a string (a-z only) longer than 7 characters, since with 7 characters there is a possible 8031810176 different combinations. you may want to check a wiki describing hash collisions in more detail. Mostly, it shouldn't be a problem, since most strings (I assume) will be readable English to some degree and minor variations will produce very different hashes.
My code is like this:
So in theory, I should recognize hash collisions at the time I write the code (the #define one), the only thing I'm afraid is: on some strange console machine, the hash string generated at run time won't match what I define at compiled time.
Some has functions will be faster than others, with more or less features. (Unicode support for ex.).
But base on the comment of the 2 functions:
CalculateHash - Calculates a hash value for a given string.
HashString - This function is Unicode agnostic and locale agnostic.
I don't know which one is better, (look like HashString won't care about Unicode & locale. But what's about CalculateHash)
I've been using a CHashedString whenever I need something to represent a hashed string and so far it's worked everywhere I've needed it. Just construct one from a string or char* and off you go.
Thank ivanhawkes, CHashedString seems interesting, I'll consider using it in complicated case.
Some older parts of my code which were basically lifted from GameSDK do have calls to CryStringUtils::HashString and use CryHash - though I expect to deprecate most of that over time.
Why do you expect that? Is the code of CryStringUtils::HashString bad?