Skip to content

Change Utils.CombineHashCodes() to use .NET Core's HashCode.Combine() method #7134

@rjmholt

Description

@rjmholt

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions