-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
After discussion in #7126 (comment) and reading various posts (1, 2, 3, 4, 5, 6), it seems like a multiplicative hash function might be better implementation than the current XOR hash used in Utils.CombineHashCodes().
Note that changing the algorithm is, by definition, not a breaking change. To quote the MSDN page on Object.GetHashCode():
A hash code is intended for efficient insertion and lookup in collections that are based on a hash table. A hash code is not a permanent value... Do not serialize hash code values or store them in databases... Do not send hash codes across application domains or processes. In some cases, hash codes may be computed on a per-process or per-application domain basis... Do not test for equality of hash codes to determine whether two objects are equal. (Unequal objects can have identical hash codes.) To test for equality, call the ReferenceEquals or Equals method.
Also, it would be worthwhile implementing an array overload of Utils.CombineHashCodes(), like Utils.CombineHashCodes(params int[] hs) and Utils.CombineHashCodes(int h, params int[] hs).