diff --git a/.gitignore b/.gitignore index 15609ffc..80bffbdd 100644 --- a/.gitignore +++ b/.gitignore @@ -339,3 +339,4 @@ ASALocalRun/ # Local History for Visual Studio Code .history/ +experiments/ diff --git a/csharp/Platform.Collections/Lists/IListExtensions.cs b/csharp/Platform.Collections/Lists/IListExtensions.cs index a39cb34e..d3ebc71f 100644 --- a/csharp/Platform.Collections/Lists/IListExtensions.cs +++ b/csharp/Platform.Collections/Lists/IListExtensions.cs @@ -336,17 +336,18 @@ public static void ForEach(this IList list, Action action) /// Хэш-код списка. /// /// - /// Based on http://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode + /// Uses System.HashCode for optimal hash combining as recommended in modern .NET applications. + /// This provides better distribution and collision resistance compared to simple multiplicative hashing. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GenerateHashCode(this IList list) { - var hashAccumulator = 17; + var hash = new HashCode(); for (var i = 0; i < list.Count; i++) { - hashAccumulator = unchecked((hashAccumulator * 23) + list[i].GetHashCode()); + hash.Add(list[i]); } - return hashAccumulator; + return hash.ToHashCode(); } /// diff --git a/csharp/Platform.Collections/Platform.Collections.csproj b/csharp/Platform.Collections/Platform.Collections.csproj index 8d027bb4..5edd89a9 100644 --- a/csharp/Platform.Collections/Platform.Collections.csproj +++ b/csharp/Platform.Collections/Platform.Collections.csproj @@ -4,7 +4,7 @@ LinksPlatform's Platform.Collections Class Library konard;tynkute Platform.Collections - 0.4.0 + 0.5.0 konard;tynkute net8 Platform.Collections @@ -24,7 +24,7 @@ true snupkg latest - Update target framework from net7 to net8. + Improve hash function quality by replacing simple multiplicative algorithm with System.HashCode for better distribution and collision resistance. enable