Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
mjp41 committed Mar 7, 2017
commit cbafaf8d58c4d3244f20a83aab58cf871ed6fbd3
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,54 @@ internal override bool IsWithinRange(T item)
return comp >= 0;
}

internal override T MinInternal
{
get
{
Node current = _root;
T result = default(T);

while (current != null) {

int comp = _lBoundActive ? Comparer.Compare(_min, current.Item) : -1;
if (comp == 1) {
current = current.Right;
} else {
result = current.Item;
if (comp == 0)
break;
current = current.Left;
}
}

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.


internal override T MaxInternal
{
get
{
Node current = _root;
T result = default(T);

while (current != null) {

int comp = _uBoundActive ? Comparer.Compare(_max, current.Item) : 1;
if (comp == -1) {
current = current.Left;
} else {
result = current.Item;
if (comp == 0)
break;
current = current.Right;
}
}

return result;
}
}

internal override bool InOrderTreeWalk(TreeWalkPredicate<T> action)
{
VersionCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,9 @@ public int RemoveWhere(Predicate<T> match)

#region ISorted members

public T Min
public T Min => MinInternal;

internal virtual T MinInternal
{
get
{
Expand All @@ -1594,7 +1596,9 @@ public T Min
}
}

public T Max
public T Max => MaxInternal;

internal virtual T MaxInternal
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ protected override int CreateT(int seed)

protected override bool DefaultValueAllowed => true;

[ActiveIssue(16760)]
[Fact]
public void SortedSet_Generic_GetViewBetween_MinMax()
{
Expand Down