Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@mjp41
Copy link
Member

@mjp41 mjp41 commented Mar 6, 2017

Fixes #16760.

Provide correct override in TreeSubSet for Min and Max, they now take
account of the range of the subset.

As the root is guaranteed to be in the range, then the code does not
need to check something is in the range, if _root is not null.

This makes Min and Max virtual. Is that an acceptable change? Previously, they hid the virtual behaviour inside the implementation.
cc @stephentoub @marek-safar @ianhays

@stephentoub
Copy link
Member

This makes Min and Max virtual. Is that an acceptable change?

Not without an API review. cc: @terrajobst
How about instead having:

public T Min => MinInternal;
internal virtual T MinInternal { get { /* code previously in Min */ } }

and then override MinInternal in TreeSubSet (and the same for Max)?

I'm not very familiar with the situations in which Min and Max would be used. Is an extra virtual call on such code paths going to be problematic for performance?

@danmoseley
Copy link
Member

A change here would require test coverage.

@stephentoub
Copy link
Member

stephentoub commented Mar 6, 2017

A change here would require test coverage.

#16763 (this PR needs to be rebased to remove the [ActiveIssue])

@mjp41 mjp41 force-pushed the SortedSet-fix branch 3 times, most recently from 2b0812c to a95f794 Compare March 6, 2017 21:29
@mjp41
Copy link
Member Author

mjp41 commented Mar 6, 2017

I rebased on top of the tests, and made it use an Internal virtual call.

@danmoseley
Copy link
Member

Shouldn't I see the [ActiveIssue] being removed?

@stephentoub
Copy link
Member

Shouldn't I see the [ActiveIssue] being removed?

It is.

@mjp41
Copy link
Member Author

mjp41 commented Mar 7, 2017

I have extended with a more exhaustive test of a small tree, so that I believe all the corner cases should be covered now.

mjp41 added 2 commits March 7, 2017 11:12
Provide correct override in TreeSubSet for Min and Max, they now take
account of the range of the subset.

As the root is guaranteed to be in the range, then the code does not
need to check something is in the range, if _root is not null.
@stephentoub
Copy link
Member

@dotnet-bot test code coverage please


return result;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nits:

  • Could you move the opening braces from the end of the lines to the beginning of the next?
  • Could you move the else to its own line?
  • Could you surround the break with braces (on their own lines)?

Same in MaxInternal below.

} else {
Assert.Equal(i + ((i+1) % 2), view.Min);
Assert.Equal(j - ((j+1) % 2), view.Max);
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: same style nits, e.g. braces

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this, @mjp41.

@mjp41
Copy link
Member Author

mjp41 commented Mar 7, 2017

@stephentoub thanks for the feedback. I have addressed the comments. Do you want me to collapse to a single commit?

@stephentoub
Copy link
Member

Thanks, @mjp41. No need; I'll just squash it when merging once CI is green.

@stephentoub stephentoub merged commit d467d43 into dotnet:master Mar 7, 2017
@karelz karelz modified the milestone: 2.0.0 Mar 7, 2017
@mjp41 mjp41 deleted the SortedSet-fix branch March 8, 2017 23:02
dcwuser added a commit to dcwuser/corefx that referenced this pull request Mar 14, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Fix behaviour of TreeSubSet Min and Max

Provide correct override in TreeSubSet for Min and Max, they now take
account of the range of the subset.

As the root is guaranteed to be in the range, then the code does not
need to check something is in the range, if _root is not null.

* Added a more exhaustive test of Min/Max on TreeSubSet.

Commit migrated from dotnet/corefx@d467d43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants