Open skyoxZ opened 2 months ago
Tagging subscribers to this area: @dotnet/area-system-collections See info in area-owners.md if you want to be subscribed.
I'm not sure what should happen if set1.comparer
, set2.comparer
and setComparer.memberEqualityComparer
are not all same. Do we support such situation?
https://learn.microsoft.com/dotnet/api/system.collections.generic.sortedset-1.createsetcomparer
I'm not sure what should happen if
set1.comparer
,set2.comparer
andsetComparer.memberEqualityComparer
are not all same. Do we support such situation?
Tricky. setComparer.memberEqualityComparer
is a IEqualityComparer
will never be equal to set1.comparer
(which is IComparer
). Documentation says they should have the same definition of equal, but it's not checked in the code nor is any behaviour documented if it doesn't hold.
Similar issue exists in HashSet<T>
:
using System;
using System.Collections.Generic;
HashSet<string> a = new();
HashSet<string> b = new(StringComparer.OrdinalIgnoreCase) { "1" };
var setComparer = HashSet<string>.CreateSetComparer();
Console.WriteLine(setComparer.Equals(b, a));
Related to #19644 and #69218. Comparing sets that encapsulate different notions of equality is inherently problematic and this shows up in the implementations that attempt to reconcile the problem. A few possible solutions have been discussed, but so far we have been hesitant to make any changes for fear of breaking code that depends subtly on the current behaviour.
Description
When
set1
andset2
have different comparers, currentSortedSetEquals
basically returnsset1.IsSubsetOf(set2)
. https://github.com/dotnet/runtime/blob/f61ca08d93fe06599f4566d6faf6f9da4cf05484/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs#L811-L828Reproduction Steps
Expected behavior
False
Actual behavior
True
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response