public void TestSetEqualsEdgeCase() { var equalityComparer = EqualityComparer <int> .Default; Func <int, int> getHashCode = value => Math.Abs(value) < 5 ? 0 : 1; var set = new TreeSet <int>(branchingFactor: 4, comparer: new SubsetHashCodeEqualityComparer <int>(equalityComparer, getHashCode)); set.UnionWith(new[] { 1, 3, 7, 9 }); Assert.False(set.SetEquals(new[] { 1, 4, 7, 9 })); }
public bool Equals(TreeSet <T>?x, TreeSet <T>?y) { if (x is null) { return(y is null); } else if (y is null) { return(false); } if (x.Comparer.Equals(y.Comparer)) { return(x.SetEquals(y)); } bool found = false; foreach (T item1 in x) { found = false; foreach (T item2 in y) { if (_comparer.Equals(item1, item2)) { found = true; break; } } if (!found) { return(false); } } return(true); }