Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structural equality and order comparison for common collections #80025

Closed
wants to merge 4 commits into from

Conversation

manandre
Copy link
Contributor

Closes #77209

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 28, 2022
@ghost
Copy link

ghost commented Dec 28, 2022

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Issue Details

Closes #77209

Author: manandre
Assignees: -
Labels:

area-System.Collections, new-api-needs-documentation

Milestone: -


[Serializable]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// Needs to be public to support binary serialization compatibility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new type. There are no binary compatibility concerns with new types. We explicitly do not want to make any new types compatible with binary serialization.

The type should be internal and all TypeForwardedFrom and Serializable attributes should be deleted from this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was not sure.
Removed!

Comment on lines +484 to +494
// if (x is Dictionary<TKey, TValue> dictx && dictx.Comparer.Equals(_keyComparer) &&
// y is Dictionary<TKey, TValue> dicty && dicty.Comparer.Equals(_keyComparer))
// {
// foreach ((TKey yKey, TValue yValue) in y)
// {
// if (!x.TryGetValue(yKey, out TValue xValue) || !_valueComparer.Equals(yValue, xValue))
// return false;
// }
//
// return true;
// }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This optimization cannot be activated here, as the Dictionary<TKey, TValue> class has the constraint where TKey : notnull which cannot be enforced here.
Is there a way to solve this?

@build-analysis build-analysis bot mentioned this pull request Dec 29, 2022
where TDictionary : System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> { throw null; }
}

public static class ComparerFactory
Copy link
Contributor Author

@manandre manandre Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approved API uses the Comparer class in the System.Collections.Generic namespace, but it is already present in the System.Collections namespace
https://github.com/dotnet/runtime/blob/5b8ebeabb32f7f4118d0cc8b8db28705b62469ee/src/libraries/System.Runtime/ref/System.Runtime.cs#L7251-L7258

Issue reported in #77209 (comment)

@manandre manandre marked this pull request as draft January 4, 2023 12:10
@manandre
Copy link
Contributor Author

manandre commented Jan 4, 2023

PR converted to draft as the approved API needs rework.

@ghost ghost closed this Feb 3, 2023
@ghost
Copy link

ghost commented Feb 3, 2023

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 5, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Collections community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add structural equality and order comparison for common collections
2 participants