The SF team advice is to use the FNV-1 hashing algorithm for this.
Select a hash algorithm An important part of hashing is selecting your
hash algorithm. A consideration is whether the goal is to group
similar keys near each other (locality sensitive hashing)--or if
activity should be distributed broadly across all partitions
(distribution hashing), which is more common.
The characteristics of a good distribution hashing algorithm are that
it is easy to compute, it has few collisions, and it distributes the
keys evenly. A good example of an efficient hash algorithm is the
FNV-1 hash algorithm.
A good resource for general hash code algorithm choices is the
Wikipedia page on hash functions.
A C# implementation in this example here:
public long HashString(string input)
{
input = input.ToUpperInvariant();
var value = Encoding.UTF8.GetBytes(input);
ulong hash = 14695981039346656037;
unchecked
{
for (int i = 0; i < value.Length; ++i)
{
hash ^= value[i];
hash *= 1099511628211;
}
return (long)hash;
}
}
Remove the ToUpperInvariant
to make it case sensitive.