You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Change Utils.CombineHashCodes() to use .NET Core's HashCode.Combine() method #7134
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
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().
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).
That code is copied from .Net here - so if you believe you have a better implementation, consider opening an issue with corefx.
I think the shift avoids the problems of xor transitivity and that shift + xor is faster than multiplication.
And last thing - an overload taking params is discouraged because it allocates memory. For non-library code, such an overload is never needed because we can always add 1 more overload that takes the exact number of parameters. Library code does not have that luxury, so libraries make the trade-off of providing a number of overloads for the most common uses and the inefficient overload for all other cases.
We have several alternative implementations of GetHashCode method in the repo.
I discovered this when I had to implement this method for SymVer type some time ago. I had the idea of opening a case on this issue but I thought that this is a very rare situation. And this question again appeared. I think we need to revise our code and if possible use the standard implementation from CoreFX.
changed the title [-]Change Utils.CombineHashCodes() to not use XOR + add array overload[/-][+]Change Utils.CombineHashCodes() to use .NET Core's HashCode.Combine() method[/+]on Jun 25, 2018
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
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
Activity
lzybkr commentedon Jun 23, 2018
That code is copied from .Net here - so if you believe you have a better implementation, consider opening an issue with corefx.
I think the shift avoids the problems of xor transitivity and that shift + xor is faster than multiplication.
And last thing - an overload taking
paramsis discouraged because it allocates memory. For non-library code, such an overload is never needed because we can always add 1 more overload that takes the exact number of parameters. Library code does not have that luxury, so libraries make the trade-off of providing a number of overloads for the most common uses and the inefficient overload for all other cases.iSazonov commentedon Jun 23, 2018
We have several alternative implementations of
GetHashCodemethod in the repo.I discovered this when I had to implement this method for
SymVertype some time ago. I had the idea of opening a case on this issue but I thought that this is a very rare situation. And this question again appeared. I think we need to revise our code and if possible use the standard implementation from CoreFX.iSazonov commentedon Jun 25, 2018
We have in .Net Core 2.1
Discussion System.HashCode
Implementation
dotnet/corefx#25013
dotnet/coreclr#14863
lzybkr commentedon Jun 25, 2018
Great, so they added a public api - best to just use that and remove the PowerShell copy.
[-]Change Utils.CombineHashCodes() to not use XOR + add array overload[/-][+]Change Utils.CombineHashCodes() to use .NET Core's HashCode.Combine() method[/+]microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.