Does a string hash exist which can ignore the order of chars in this string

hash

Solution

There is a number of different approaches you can take.

You can add the values of the characters together. (a + b + c is equal to a + c + b.) Unfortunately, this is the least desirable approach, since strings like "ac" and "bb" will generate the same hash value.

To reduce the possibility of hash code collisions, you can XOR the values together. (a ^ b ^ c is equal to a ^ c ^ b.) Unfortunately, this will not give a very broad distribution of random bits, so it will still give a high chance of collisions for different strings.

To even further reduce the possibility of hash code collisions, you can multiply the values of the characters together. (a * b * c is equal to a * c * b.)

If that's not good enough either, then you can sort all the characters in the string before applying the default string hashing function offered to you by whatever language it is that you are using. (So, both "helloword" ad "wordhello" would become "dehlloorw" before hashing, thus generating the same hash code.) The only disadvantage of this approach is that it is computationally more expensive than the others.

Problem

Does a string hash exist which can ignore the order of chars in this string? Eg."helloword" and "wordhello" can map into the same bucket.

Original source