-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixed the equality contract on Metrics type #7733
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
Conversation
`SetEqual` is available since .NET Fx 3.5 and is destined for equality comparison of two different hash set instances. Since both instances of the `Metrics` type has the same default comparer, the method works as a sugar over a length check followed by iteration over one set and probing the second one for containing the current element through the `Contains` method.
`HashSet<T>` doesn't override `GetHashCode`. Therefore, the default provided algorithm for reference types is used which doesn't take fields into account as it happens for value types. That breaks the equality contracts on Metrics. Ideally `HashCode` type should be used for more correct computations with less number of collisions, but that requires increasing the minimal target framework.
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
Thank you for your submission. We will review this in due course as and when someone is available on the team to do so. |
Thanks as well for this contribution! It might be worth adding a conditional reference to For now I'm going to approve the PR to have this fix included in the next patch release. The |
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
* DoubleWithFractionalPortionConverter and FloatWithFractionalPortionConverter should not fall through to always throw a JSONException for non NETCore builds (#7753) * Complted buckets JSON converter (#7738) * Boosted non-exhaustive enum deserialization (#7737) * Optimized `FieldConverter` (#7736) * Removed unused JsonIgnore (#7735) * Fixed the equality contract on Metrics type (#7733) * No allocations in ResponseItem IsValid prop (#7731) * Refactoring and tiny behavior fix for Ids (#7730) --------- Co-authored-by: Florian Bernd <[email protected]> Co-authored-by: Karl-Johan Sjögren <[email protected]> Co-authored-by: Yoh Deadfall <[email protected]>
HashSet<T>
doesn't overrideGetHashCode
. Therefore, the default provided algorithm for reference types is used which doesn't take fields into account as it happens for value types. That breaks the equality contracts on Metrics.Ideally
HashCode
type should be used for more correct computations with less number of collisions, but that requires increasing the minimal target framework.SetEqual
is available since .NET Fx 3.5 and is destined for equality comparison of two different hash set instances. Since both instances of theMetrics
type has the same default comparer, the method works as a sugar over a length check followed by iteration over one set and probing the second one for containing the current element through theContains
method.