I have a structure having 3 integers in [1, 1000] and string.
I need to represent it in 32 bit number such that two structures differing in at least one field would produce different codes, while structures having the same content consistently produce the same code. Usually one of the integer fields would be increased in several units. This should necessarily produce a different code.
At first, I thought to format the structure fields to a string in a constant format and then to hash it using GetHashCode function of String class. But then I read here in some discussions that repeating process runs on the same input don't necessary produce the same hash output. First of all, is this true in .NET 4? It's important to me, because the hash values should be persisted and stay consistent over process runs. I also saw here suggestions to perform bitwise operations of results of the platform GetHashCode applied on each structure field using prime numbers. But here again, apparently I can't count on the consistent result of the process runs.
If I use cryptographic hash functions, I exceed 32 bit.
If I didn't have a string field, I would compose the code as a 32 bit array from the numeric fields. May be it's worth to XOR such bit array with the string field GetHashCode result? Do I increase chances that repeating run on some input will produce the same hash output?
What would you suggest to do?