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

Simpler TreeTrie.isEmpty() method #9075

Merged
merged 6 commits into from
Dec 21, 2022

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Dec 20, 2022

Avoid creating (Key)Set to just test for empty.

Avoid creating (Key)Set to just test for empty.
@joakime joakime requested review from gregw and lorban December 20, 2022 20:51
@joakime joakime self-assigned this Dec 20, 2022
@joakime joakime added this to the 12.0.x milestone Dec 20, 2022
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Other than a rename LGTM

Comment on lines 279 to 303
return !hasAnyKey(_root);
}

private boolean hasAnyKey(Node<V> t)
{
if (t != null)
{
if (t._key != null)
return true;

for (int i = 0; i < INDEX; i++)
{
if (t._nextIndex[i] != null)
{
if (hasAnyKey(t._nextIndex[i]))
return true;
}
}
for (int i = t._nextOther.size(); i-- > 0; )
{
if (hasAnyKey(t._nextOther.get(i)))
return true;
}
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

probably invert the boolean and rename isEmpty(Node)

Copy link
Contributor Author

@joakime joakime Dec 20, 2022

Choose a reason for hiding this comment

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

Inverted / Renamed

Copy link
Contributor

@lorban lorban left a comment

Choose a reason for hiding this comment

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

This looks alright, but I think we should add some testing to cover the two loops in isEmpty(Node).

if (t._key != null)
return false;

for (int i = 0; i < INDEX; i++)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some test coverage for this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, the first loop is 100% covered by the 2 new test cases.
The second loop executes, but nothing can trigger the internal isEmpty() logic with the test cases as it stands.

@joakime joakime merged commit fe74264 into jetty-12.0.x Dec 21, 2022
@joakime joakime deleted the fix/jetty-12.0.x/treetrie-isempty-redux branch December 21, 2022 18:46
@gregw
Copy link
Contributor

gregw commented Dec 21, 2022

I just pushed 3d4bb49 which slightly improves the test coverage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants